Furkan
22nd November 2010, 20:12
Hello.
QString text = selectedText();
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())
{
QString truncatedURL = text;
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);
a->setData(QUrl(text));
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);
a->setData(QUrl(text));
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
//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!
QString text = selectedText();
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())
{
QString truncatedURL = text;
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);
a->setData(QUrl(text));
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);
a->setData(QUrl(text));
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
//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!