Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved]QNetworkAccessManager, finished slot called immidiately before loading..
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved General and Desktop
10 Posts 3 Posters 5.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    Zain
    wrote on last edited by
    #1

    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.

    Zain

    1 Reply Last reply
    0
    • A Offline
      A Offline
      AcerExtensa
      wrote on last edited by
      #2

      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...

      God is Real unless explicitly declared as Integer.

      1 Reply Last reply
      0
      • Z Offline
        Z Offline
        Zain
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          AcerExtensa
          wrote on last edited by
          #4

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

          God is Real unless explicitly declared as Integer.

          1 Reply Last reply
          0
          • Z Offline
            Z Offline
            Zain
            wrote on last edited by
            #5

            Its an https://

            1 Reply Last reply
            0
            • T Offline
              T Offline
              tomma
              wrote on last edited by
              #6

              And reply doesn't return any errors?

              1 Reply Last reply
              0
              • Z Offline
                Z Offline
                Zain
                wrote on last edited by
                #7

                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.

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  AcerExtensa
                  wrote on last edited by
                  #8

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

                  God is Real unless explicitly declared as Integer.

                  1 Reply Last reply
                  0
                  • Z Offline
                    Z Offline
                    Zain
                    wrote on last edited by
                    #9

                    @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?....

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      AcerExtensa
                      wrote on last edited by
                      #10

                      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...

                      God is Real unless explicitly declared as Integer.

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved