PDA

View Full Version : QNetworkAccessManager->get problem (no matching function)



Cucus
1st September 2011, 05:51
I've checked lots of examples and this code is supposed connect to google.com


QNetworkAccessManager * Network_Manager;
Network_Manager = new QNetworkAccessManager(this);
QString URL;
URL = "http://www.google.com/";
QNetworkRequest netRequest(QUrl(URL));
Network_Manager->get(netRequest);

But I get this error when trying to compile:


error: no matching function for call to QNetworkAccessManager::get(QNetworkRequest (&)(QUrl))'
candidates are: QNetworkReply* QNetworkAccessManager::get(const QNetworkRequest&)

I've added
#include <QNetworkAccessManager>
#include <QtNetwork>
and
QT += network in my .pro

thanks in advance...

Cucus
1st September 2011, 21:18
No one?
Could this be a bug??
I've tried it with version 4.7.3 and 4.8.0 beta...

just_usr
14th September 2019, 18:43
I just got the same error. It is not bug but c++ syntax. Compilator thinks that QNetworkRequest netRequest(QUrl(URL)); is a function declaration. Yes we can make a declaration in another function. In the error you get
QNetworkRequest (&)(QUrl) - is a function type. But its still weird why we can declare function argument with its initialization?? QUrl uri in param-list its clear, but i dunno what could QUrl(uri) mean.

You need to replace your line 5 with QNetworkRequest netRequest = QNetworkRequest(QUrl(URL));

sry for late response, mb someone else gets stuck in that.:confused: