Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved QNetworkReply takes long time to emit finished signal

    General and Desktop
    qnetworkreply qnetworkrequest qt5 delay header
    2
    7
    3601
    Loading More Posts
    • 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.
    • T
      Tusharh last edited by A Former User

      I am trying to read a header value from reply for which I had fired a request. First, it didn't use to give any reply.Later,I added an event loop to know when the Finished signal is received. I now, get the reply properly,but problem now I am facing is that it takes huge time to reply. Nearly 10 seconds..!!! I receive the reply immediately after firing the request.I can see it in fiddler(a packet capturing tool). Why is it taking 10 seconds when it has all the values?

      my chunk of code -

      bool MySampleApp::getStatus()
      {
      QNetworkRequest request;
      QUrl url ("http://www.myapp.com");
      QString strQuery = "myquerytoserver";
      url.setEncodedQuery(strQuery.toUtf8());
      request.setUrl();
      m_networkManager = new QNetworkAccessManager(this);
      request.setSslConfiguration(this->createSslConfig());
      QNetworkReply *reply = m_networkManager->sendCustomRequest(request,"HEAD");

      QEventLoop loop;
      connect(reply, SIGNAL(finished()), &loop, SLOT(quit())); //10 seconds??? why??
      loop.exec();
      
       if(reply)
      {
         reply->deleteLater();
         QByteArray strPresent =  reply->rawHeader("is_present"); // my custom header value sent by server
         if("true" == strPresent)
            return true;
      }
      return false;
      

      }

      Thanks in advance..!!

      1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        Hi,

        Are you sure that all data have arrived that soon ? Getting the headers and getting everything that the request has asked for are two different things

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        T 1 Reply Last reply Reply Quote 0
        • T
          Tusharh @SGaist last edited by

          @SGaist Yes.I immediately get all the data in the response/reply. But, here as I mentioned it takes huge time to emit finished. When multiple requests are fired, their 10 seconds adding up literally hangs up my app.

          1 Reply Last reply Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion last edited by

            Does the server keep the connection open too long ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            T 1 Reply Last reply Reply Quote 0
            • T
              Tusharh @SGaist last edited by

              @SGaist No,server doesn't keep connection open to long. Does it have to do something with networkacessmanager? It's used through out the app & some requests have timers associated with them. But, I don't use timer for my this particular request.

              1 Reply Last reply Reply Quote 0
              • SGaist
                SGaist Lifetime Qt Champion last edited by

                How many queries are you sending at the same time ?

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                T 1 Reply Last reply Reply Quote 0
                • T
                  Tusharh @SGaist last edited by

                  @SGaist Hi, I resolved the issue. I was actually firing sendCustomRequest() api as I was using a specific url query in request which was needed in to fire via HEAD method. Before firing sendCustomRequest() api I was also creating & resetting my ssl configuration. So, instead I directly now use the head() api to fire my HEAD request. Now,finished signal by reply gets fired instantaneously & I am able to read my specific header value in response in no time.

                  Thanks for your time..!! :)

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post