我在撰写Qt网络代码时有疑问。
我使用QNetworkAccessManager
来获取一系列网页,例如:
www.google.com/1.php
www.google.com/2.php
www.google.com/3.php
...
并且可能不存在大号页面,例如www.google.com/50.php
。
我的代码如下:
class mythread: public QThread
{
protected:
void run()
{
connect(manager,SIGNAL(finished(QNetworkReply*)),
this,SLOT(replyFinished(QNetworkReply*)));
for(int i=1 ; i<=20;i++)
{
QString tmpurl = [URL]+"/"+i ;
request->setUrl(tmpurl);
reply = manager->get(*request);
reply->waitForReadyRead(2000);
}
}
void replyFinished(QNetworkReply *r)
{
/*...
if the tmpUrl web page not found ,
then
print "NOT FOUND"
else
print "FOUND"
...
*/
}
private:
QNetworkAccessManager *manager ;
QNetworkRequest *request ;
QNetworkReply *reply ;
};
当我运行代码时,结果是:
NOT FOUND
NOT FOUND
FOUND
FOUND
NOT FOUND
NOT FOUND
....
如何按顺序保留QNetworkReply
s readyread
信号?
我想要结果湖:
FOUND
FOUND
NOT FOUND
NOT FOUND
NOT FOUND
NOT FOUND
...