本文介绍了QNetworkAccessManager没有完成信号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想直接请求和响应,而不是使用connect(..,SLOT(finished()),..,SLOT())
I want to request and response directly instead of using connect(..,SLOT(finished()),..,SLOT())
推荐答案
您可以使用QEventLoop
,以便应用程序等待并可以同时处理其他事件.
You can use a QEventLoop
so that the application waits and can handle other events at the same time.
#include <QCoreApplication>
#include <QNetworkAccessManager>
#include <QNetworkReply>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QNetworkAccessManager *manager = new QNetworkAccessManager;
QEventLoop loop;
QObject::connect(manager, &QNetworkAccessManager::finished, &loop, &QEventLoop::quit);
QNetworkReply *reply = manager->get(QNetworkRequest(QUrl("https://api.github.com/events")));
loop.exec();
qDebug()<<reply->readAll();
delete reply;
delete manager;
return 0;
}
这篇关于QNetworkAccessManager没有完成信号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!