-1

This is the code :

QEventLoop eventLoop;
QNetworkAccessManager mgr();
QObject::connect(mgr, SIGNAL(finished(QNetworkReply*)), &eventLoop, SLOT(quit()));
QUrl url(site);
QNetworkRequest req(url);
QNetworkReply *reply = mgr.get(req);
eventLoop.exec();

if (reply->error() == QNetworkReply::NoError) {
    cout << "Success" endl;
    delete reply;
}
else {
    cout << "Failure" endl;
    delete reply;
}

Errors found:

.. \ request.cpp (17): error C2665: 'QObject :: connect': none of 3 overload could convert all kinds of topics

and

.. \ request.cpp (20): error C2228: the element to the left of '.get' must be a class, structure or union

2 Answers2

3

This is called most vexing parse, the compiler thinks that mgr is a function declaration. To fix this, just change

QNetworkAccessManager mgr();

to

QNetworkAccessManager mgr;

You also have an error in your connect, it should look like this (notice the & before mgr, since connect expects pointers):

QObject::connect(&mgr, SIGNAL(finished(QNetworkReply*)), &eventLoop, SLOT(quit()));
SingerOfTheFall
  • 29,228
  • 8
  • 68
  • 105
1

You have extra brackets. Use:

QNetworkAccessManager mgr;

QNetworkAccessManager does not have constructor without arguments, so parser understands it like function declaration. Also you probably get warning in second line, like:

: warning: empty parentheses interpreted as a function declaration [-Wvexing-parse]
QNetworkAccessManager mgr();
                         ^~
prajmus
  • 3,171
  • 3
  • 31
  • 41
RazrFalcon
  • 787
  • 7
  • 17