Originally Posted by
jefftee
Do you have an event loop running?
The requests will all be performed asynchronously, so until you return from whatever method you're executing above and re-enter your event loop, you won't receive any signals.
You mean that I need to set a flag to make "for" loop blocked until I received the previous reply?
void class1::fun1()
{
QNetworkAccessManager* pManager = new QNetworkAccessManager(this);
connect(pManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(read(QNetworkReply*)));
int iPageCount = 2000;
for (int i = 0; i < iPageCount; ++i)
{
QNetworkRequest request;
request.
setUrl(QString("http://www.abc.com/%1.html").
arg(QString::number(i
)));
pManager->get(request);
m_bFlag = true;
while (m_bFlag)
{
qApp->processEvents();
}
}
}
void class1::read(QNetworkReply* pReply)
{
pReply->abort();
pReply->close();
pReply->deleteLater();
m_bFlag = false;
}
void class1::fun1()
{
QNetworkAccessManager* pManager = new QNetworkAccessManager(this);
connect(pManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(read(QNetworkReply*)));
int iPageCount = 2000;
for (int i = 0; i < iPageCount; ++i)
{
QNetworkRequest request;
request.setUrl(QString("http://www.abc.com/%1.html").arg(QString::number(i)));
pManager->get(request);
m_bFlag = true;
while (m_bFlag)
{
qApp->processEvents();
}
}
}
void class1::read(QNetworkReply* pReply)
{
QByteArray array = pReply->readAll();
pReply->abort();
pReply->close();
pReply->deleteLater();
m_bFlag = false;
}
To copy to clipboard, switch view to plain text mode
Originally Posted by
anda_skoa
You forgot to post the code of that method. Hard to tell if you have a mistake in your code without seeing it.
Cheers,
_
That code just to read the byte array and called a function to parsed it, like this:
void class1::read(QNetworkReply* pReply)
{
pReply->abort();
pReply->close();
pReply->deleteLater();
parse(array);
}
void class1::parse(const QByteArray& array)
{
...
}
void class1::read(QNetworkReply* pReply)
{
QByteArray array = pReply->readAll();
pReply->abort();
pReply->close();
pReply->deleteLater();
parse(array);
}
void class1::parse(const QByteArray& array)
{
...
}
To copy to clipboard, switch view to plain text mode
Bookmarks