How to wait till QNetworkReply gives a result
Hello.
Code:
text = text.trimmed();
text.insert(0, "http://www.");
QNetworkAccessManager *manager = new QNetworkAccessManager(this);
QNetworkReply
*reply
= manager
->head
(QNetworkRequest
(QUrl(text
)));
//QMessageBox::information(this,"asd","asdasd");
QVariant variant
= reply
->header
(QNetworkRequest
::LocationHeader);
if(!variant.isNull())
{
if (text.length() > 18)
{
truncatedURL.truncate(15);
truncatedURL += "...";
}
//open selected text url in a new tab
a = new KAction(KIcon("tab-new"), i18n("Open '%1' in New Tab", truncatedURL), this);
connect(a, SIGNAL(triggered(bool)), this, SLOT(openLinkInNewTab()));
menu.addAction(a);
//open selected text url in a new window
a = new KAction(KIcon("window-new"), i18n("Open '%1' in New Window", truncatedURL), this);
connect(a, SIGNAL(triggered(bool)), this, SLOT(openLinkInNewWindow()));
menu.addAction(a);
menu.addSeparator();
}
The purpose of the code is to check whether selected text is an URL to a web site or not. When I uncomment this line
Code:
//QMessageBox::information(this,"asd","asdasd");
it works fine. But when I comment that line it doesn't! I think the application can have enough time to compute the QNetworkReply result. I don't know how to solve the problem, please help me!
Thanks in advance!
Re: How to wait till QNetworkReply gives a result
Replace
Code:
//QMessageBox::information(this,"asd","asdasd");
with
Code:
while (!reply->isFinished());
To wait while request is being processed.
MT.
Re: How to wait till QNetworkReply gives a result
Quote:
Originally Posted by
mac.tieu
Replace
Code:
//QMessageBox::information(this,"asd","asdasd");
with
Code:
while (!reply->isFinished());
To wait while request is being processed.
MT.
That will block the program.
Instead, use signals and slots. http://doc.qt.nokia.com/4.7/qnetwork....html#finished
Re: How to wait till QNetworkReply gives a result