没有完成信号的 QNetworkAccessManager
QNetworkAccessManager without finished signal
我想直接请求和响应而不是使用 connect(..,SLOT(finished()),..,SLOT())
您可以使用 QEventLoop
以便应用程序等待并可以同时处理其他事件。
#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;
}
我想直接请求和响应而不是使用 connect(..,SLOT(finished()),..,SLOT())
您可以使用 QEventLoop
以便应用程序等待并可以同时处理其他事件。
#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;
}