QNetworkAccessManager *manager = new QNetworkAccessManager(); QNetworkReply *reply = manager->get(QNetworkRequest(QUrl(url))); QByteArray responseData; QEventLoop eventLoop; QObject::connect(manager, SIGNAL(finished(QNetworkReply *)), &eventLoop, SLOT(quit())); eventLoop.exec(); responseData = reply->readAll();
当调用事件的exec()的时候,程序就会在exec()里面无限循环,不会执行后面的代码,除非程序调用exit()从exec()里面跳出来。