C++ 我的qhttp get()调用在Windows上不起作用,但在Linux上起作用
我已经写了一个程序,使用qhttp获取网页。这在Linux上运行良好,但在我的Windows box(Vista)上不起作用。似乎从未收到qhttp done信号 有关守则如下:C++ 我的qhttp get()调用在Windows上不起作用,但在Linux上起作用,c++,qt,get,C++,Qt,Get,我已经写了一个程序,使用qhttp获取网页。这在Linux上运行良好,但在我的Windows box(Vista)上不起作用。似乎从未收到qhttp done信号 有关守则如下: Window::Window() { http = new QHttp(this); connect(http, SIGNAL(done(bool)), this, SLOT(httpDone(bool))); url = new QUrl("http://something.com/statu
Window::Window()
{
http = new QHttp(this);
connect(http, SIGNAL(done(bool)), this, SLOT(httpDone(bool)));
url = new QUrl("http://something.com/status.xml");
http->setHost(url->host(), url->port() != -1 ? url->port() : 80);
if (!url->userName().isEmpty()) http->setUser(url->userName(), url->password());
}
void Window::retrievePage()
{
byteArray = new QByteArray;
result = new QBuffer(byteArray);
result->open(QIODevice::WriteOnly);
httpRequestAborted = false;
httpGetId = http->get(url->path(), result);
}
void Window::httpDone(bool error)
{
//Never gets here!
}
任何帮助都将被告知
Matt这根本不应该发生,即QHttp在Windows和Unix上都能可靠地工作 我的建议是检查发球者的反应是否正确。这可以通过验证数据传输是否正常来实现。您可以从QHttp的信号(例如)和其他相关信号跟踪状态
另一方面,与其使用旧的QHttp,为什么不使用推荐的QHttp呢?为了让你的脚快速湿润,请查看我不久前发布到Qt实验室的一个示例:。它使用said从删除的URL抓取图像。检查,只有150行。按照Ariya的建议重新编写,以使用QNetworkAccessManager并查看 现在,它可以在Windows和Linux上运行
Window::Window()
{
connect(&manager, SIGNAL(finished(QNetworkReply*)),
this, SLOT(retrieveData(QNetworkReply*)));
}
void Window::retrieveMessage()
{
manager.get(QNetworkRequest(QUrl("http://...")));
}
void Window::retrieveData(QNetworkReply *reply)
{
QVariant statusCodeV =
reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
// "200 OK" received?
if (statusCodeV.toInt()==200)
{
QByteArray bytes = reply->readAll(); // bytes
}
reply->deleteLater();
}
你能确定这不是UAC的问题吗?尝试关闭UAC,如果您看到任何安全弹出窗口,请告诉我们。谢谢。我现在已经试过了,但仍然不起作用。后来我在XP机器上试用过,也遇到了同样的问题。