Important: Please read the Qt Code of Conduct -

[Solved]QNetworkAccessManager, finished slot called immidiately before loading..

  • Hello experts,

    I am facing a strange problem with the QNetworkAccessManager.
    When I run the program in Qt creator IDE it works fine, but when I run this from debug or release folder it creates the issue.
    The ReplyFinished slot for finished signal of QNetworkAccessManager fired immidiately before the load finished :
    Here is the code:

    void MainWindow::collectUrls()
    QNetworkAccessManager *manager;
    manager = new QNetworkAccessManager ();
    QNetworkRequest req;
    req.setUrl(QUrl("My url"));
    //Configure the parameters for the post request:
    QByteArray postData;

    postData.append("my data");
     //Now create a QCookieJar:
    req.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
    manager->setCookieJar(new QNetworkCookieJar(manager));
    connect(manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(replyFinish (QNetworkReply  *)));
    //Send the request:
    manager->post(req, postData);


    void MainWindow::replyFinish(QNetworkReply *reply)

     QString answer = QString::fromUtf8(reply->readAll());
     qDebug () << answer;        


    Its a strange behavior.. because it runs fine when I run the program in IDE, It comes in the slot only when the load finished.
    But while running the .exe in debug/release folder it run like a simple function call and does not wait for the finishing the url page load, and returns blank result.

    Any help appreciated.
    Thanks in advance.


  • Maybe Qt libraries are mixed up.... Is it console app? Are you sure it runs at all?
    copy exe file into separate folder, copy QtCore, Network and other needed libs in the same folder. Run your app.

    P.S.: also add qDebug() somethere in collectUrls function... just to be sure...

  • Thanks for the reply..

    -I am sure that the program runs.. I have run it several times and it worked fine in IDE for both running and debugging, It creates problems only when I try to run the .exe file from debug /release folder .
    -Its a GUI application, I am calling collectUrls() in mainwindow constructor (to run it at start up).
    -I have added all the necessary libraries already and also double checked these.

    The issue is still there.

  • Strange... and url you are calling is not https? Right?

  • Its an https://

  • And reply doesn't return any errors?

  • No errors at all.. It just doesn't give me the result.. Its working as a simple function call and not as a slot. It should wait till the page load and should fire when load is finished. But it runs immediately , same as a function call.
    Any other ideas??
    Please help to resolve this issue.. Its a critical situation.

  • have you also copied libeay32 and ssleay32 to the same folder with exe?

  • @AcerExtensa

    I just added both the dlls and...
    At last...........You did the trick (and its a treat for me)....thanks a lot ....
    :) :) :)
    ... can you explain how does it work?....

  • Qt loads ssl libs dynamically(if not compiled with openssl-linked), so ssl libs should be in system library path or in the same folder to get loaded by Qt. And if this libs are not found, you don't even get SSLError fired, thats because your finished slot was fired just after calling post method of QNAM without any error and of cause without any reply...

Log in to reply