Qt Forum

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

    Update: Forum Guidelines & Code of Conduct

    [SOLVED] QNetworkAccessManager::get timeout?

    General and Desktop
    qnetworkaccessm
    4
    7
    4748
    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.
    • F
      floatingWoods last edited by floatingWoods

      Hello,

      how can I control the timeout of a QNetworkAccessManager::get?
      I mean, if there is no internet connection, or the file is not available/reachable, how long will it try before giving up? Do I have a control over the timeout?

      Thanks

      p3c0 MayEnjoy 2 Replies Last reply Reply Quote 0
      • p3c0
        p3c0 Moderators @floatingWoods last edited by

        @floatingWoods Since there is still no built-in way to do that you will have to rely on implementing your own Timers for aborting it after a particular time.

        157

        1 Reply Last reply Reply Quote 1
        • MayEnjoy
          MayEnjoy @floatingWoods last edited by

          @floatingWoods said:

          QNetworkAccessManager::get

          Here is a demo.

          I am a engineer.

          1 Reply Last reply Reply Quote 1
          • M
            mcosta last edited by

            Hi,

            the timer solution suggested by @p3c0 and @MayEnjoy is OK.
            Is important to call QNetworkReply::abort() in the timeout handle otherwise network resources will be not freed.

            Once your problem is solved don't forget to:

            • Mark the thread as SOLVED using the Topic Tool menu
            • Vote up the answer(s) that helped you to solve the issue

            You can embed images using (http://imgur.com/) or (http://postimage.org/)

            1 Reply Last reply Reply Quote 1
            • F
              floatingWoods last edited by

              Thank you both for the good suggestions!

              A last related question: how can I simulate a long timeout? I am trying to get a file with:

              networkAccessManager->get(QNetworkRequest(QUrl("http://www.google.com/aFile.txt")));
              

              When I enter an invalid address or an inexistant file, the finished signal is fired after 1-2 seconds only, which wouldn't be a problem. I want to avoid the other, much longer timeouts that can last up to 30 seconds. And to provoque this long waiting time, how should my code line look like?

              Thanks

              1 Reply Last reply Reply Quote 0
              • M
                mcosta last edited by

                You can create your own web server (for example with Python SimpleHTTPServer and simulate a long time response

                Once your problem is solved don't forget to:

                • Mark the thread as SOLVED using the Topic Tool menu
                • Vote up the answer(s) that helped you to solve the issue

                You can embed images using (http://imgur.com/) or (http://postimage.org/)

                1 Reply Last reply Reply Quote 1
                • F
                  floatingWoods last edited by

                  Thanks mcosta!

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