QNetwotkAccessManages::get() 函数会持续一段时间(大约 7-10 秒),获取在任何浏览器中都可以立即打开的页面。
实际上,我尝试获取http://suggestqueries.google.com/complete/search?client=chrome&q=myrequest。
这是简化的代码:
void ApiGoogleSearch::getSuggestions()
{
QNetworkAccessManager *manager = new QNetworkAccessManager(this);
connect(manager, SIGNAL(finished(QNetworkReply*)),
SLOT(getSuggestionsFinished(QNetworkReply*)));
QUrl url("http://suggestqueries.google.com/complete/search"
"?client=chrome&q=myrequest");
manager->get(QNetworkRequest(url));
qDebug() << "get() started";
}
void ApiGoogleSearch::getSuggestionsFinished(QNetworkReply *reply)
{
qDebug() << "ApiGoogleSearch::getSuggestionsFinished() started";
}