gpt4 book ai didi

c++ - 我的 qhttp get() 调用在 Windows 上不起作用,但在 Linux 上起作用

转载 作者:行者123 更新时间:2023-11-30 04:40:45 25 4
gpt4 key购买 nike

我写了一个使用qhttp获取网页的程序。这在 Linux 上运行良好,但在我的 Windows 机器 (Vista) 上不起作用。似乎从未收到 qhttp 完成信号。

相关代码为:

    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!
}

如有任何帮助,我们将不胜感激。

马特

最佳答案

这根本不应该发生,即 QHttp 在 Windows 和 Unix 上都能可靠地工作。

我的建议是检查发球是否给出了正确的 react 。这可以做到,例如通过验证数据传输是否正常。您可以从 QHttp 的信号中跟踪状态,例如dataReadProgress , requestStarted , requestFinished , 以及其他相关信号。

另一方面,与其使用旧的 QHttp,不如使用推荐的 QNetworkAccessManager反而?为了让您快速上手,请查看我之前发布到 Qt Labs 的示例:image viewer with remote URL drag-and-drop support .它使用所述 QNetworkAccessManager从拖放的 URL 中抓取图像。检查source-code ,只有 150 行。

关于c++ - 我的 qhttp get() 调用在 Windows 上不起作用,但在 Linux 上起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/803088/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com