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::get timeout?

[SOLVED] QNetworkAccessManager::get timeout?

Scheduled Pinned Locked Moved General and Desktop
qnetworkaccessm
7 Posts 4 Posters 5.3k Views
  • 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 Offline
    F Offline
    floatingWoods
    wrote on last edited by floatingWoods
    #1

    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

    p3c0P MayEnjoyM 2 Replies Last reply
    0
    • F 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

      p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      @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
      1
      • F 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

        MayEnjoyM Offline
        MayEnjoyM Offline
        MayEnjoy
        wrote on last edited by
        #3

        @floatingWoods said:

        QNetworkAccessManager::get

        Here is a demo.

        I am a engineer.

        1 Reply Last reply
        1
        • M Offline
          M Offline
          mcosta
          wrote on last edited by
          #4

          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
          1
          • F Offline
            F Offline
            floatingWoods
            wrote on last edited by
            #5

            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
            0
            • M Offline
              M Offline
              mcosta
              wrote on last edited by
              #6

              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
              1
              • F Offline
                F Offline
                floatingWoods
                wrote on last edited by
                #7

                Thanks mcosta!

                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