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. Handling network timeout in Qt
Forum Updated to NodeBB v4.3 + New Features

Handling network timeout in Qt

Scheduled Pinned Locked Moved General and Desktop
4 Posts 4 Posters 4.9k Views 2 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.
  • S Offline
    S Offline
    shismitt
    wrote on 18 Aug 2012, 21:22 last edited by
    #1

    When dealing with QNetworkReply, it is "prescribed":http://qt-project.org/forums/viewthread/11763 to use timers to abort the connection.

    Here is my current code:
    @void ImageDownloader::download(QString imgUrl){
    this->timeoutTimer = new QTimer(this);
    this->timeoutTimer->setSingleShot(true);
    this->timeoutTimer->setInterval(15000);
    connect(this->timeoutTimer, SIGNAL(timeout()), this, SLOT(timeout()));

    QUrl requestUrl(imgUrl);
    QNetworkRequest nwRequest(requestUrl);
    this->imageNwReply = this->nam->get(nwRequest);
    connect(imageNwReply,SIGNAL(finished()),this,SLOT(imgDownloaded()));
    connect(imageNwReply, SIGNAL(downloadProgress(qint64,qint64)), this->timeoutTimer, SLOT(start()));
    this->timeoutTimer->start();
    }

    void ImageDownloader::timeout(){
    qDebug()<<FUNCTION<<" Forced timeout!";
    this->imageNwReply->abort();
    }@

    The confusion I am facing is when should I start the timer? At times I have to make around 50 concurrent Get requests from QNetworkAccessManager but since there is "throttling for maximum concurrent connections":http://www.qtcentre.org/threads/37530-QNetworkAccessManager-only-6-requests-are-executed-in-parallel-for-one-host, at times it happens that some of the requests get timed out even before they have been processed.

    Is there a signal to know exactly when the processing for a request is started by QNeworkAccessManager so that I can start the corresponding timer only then?

    One possible solution might be to implement a Queue of requests and have only the maximum possible connections to process but I am looking for a cleaner solution

    1 Reply Last reply
    0
    • R Offline
      R Offline
      rcari
      wrote on 21 Aug 2012, 07:53 last edited by
      #2

      This has been an open question for a while now given this "bug report":https://bugreports.qt-project.org/browse/QTBUG-3443. It does not seem to be a priority.

      E 1 Reply Last reply 18 Nov 2019, 17:51
      0
      • A Offline
        A Offline
        AcerExtensa
        wrote on 21 Aug 2012, 07:59 last edited by
        #3

        Just an idea, but maybe subclass QNetworkAccessManager, reimplement createRequest function and start the timer there?
        There is also downloadProgress signal in QNetworkReply, but it will be only called if connection is already established to the server, so it's useless in your situation...

        God is Real unless explicitly declared as Integer.

        1 Reply Last reply
        0
        • R rcari
          21 Aug 2012, 07:53

          This has been an open question for a while now given this "bug report":https://bugreports.qt-project.org/browse/QTBUG-3443. It does not seem to be a priority.

          E Offline
          E Offline
          ekkescorner
          Qt Champions 2016
          wrote on 18 Nov 2019, 17:51 last edited by
          #4

          @rcari said in Handling network timeout in Qt:

          This has been an open question for a while now given this "bug report":https://bugreports.qt-project.org/browse/QTBUG-3443. It does not seem to be a priority.

          finally a 10 yrs old bug is fixed for Qt 5.15 :)
          https://codereview.qt-project.org/c/qt/qtbase/+/278064

          ekke ... Qt Champion 2016 | 2024 ... mobile business apps
          5.15 --> 6.8 https://t1p.de/ekkeChecklist
          QMake --> CMake https://t1p.de/ekkeCMakeMobileApps

          1 Reply Last reply
          5

          • Login

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