能否将《Qt法典》引入一个无限的漏洞?
QNetworkAccessManager m;
QNetworkReply *reply = m.get(QNetworkRequest(QUrl("http://www.example.org/")));
QEventLoop loop;
QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
loop.exec();
qDebug() << reply->readAll();
delete reply;
这基本上是显示网页内容的“同步”方式。
我没有注意到任何使用它的问题,但我考虑了以下设想:
- The
finished
signal ofreply
is emitted before the event loop is created and the signal-slot connection betweenfinished
andquit
is made - No signal will be emitted from that point forward thus never triggering
quit
loop.exec()
will continually loop
这样做是可能的,还是我不了解Qt事件如何运作?