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. QNetworkAccessManager timeout
QtWS25 Last Chance

QNetworkAccessManager timeout

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 6.1k 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
    fronald
    wrote on last edited by
    #1

    Hi guys,

    How to do a request with timeout using QNetworkAccessManager and QNetworkRequest API?

    @
    QNetworkAccessManager *nam = new QNetworkAccessManager(this);
    QString url("http://myhost.com.br");
    QNetworkReply *reply= nam->get(QNetworkRequest(url));
    connect(reply, SIGNAL(finished()),&loop, SLOT(quit()));
    loop.exec();
    @

    Thanks!

    1 Reply Last reply
    0
    • K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      I would assume that you check with the "error method":http://qt-project.org/doc/qt-4.8/qnetworkreply.html#error for a time-out. Also you may connect to the "error signal.":http://qt-project.org/doc/qt-4.8/qnetworkreply.html#error-2

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      0
      • F Offline
        F Offline
        fronald
        wrote on last edited by
        #3

        Thank you! That error signal is very useful for me now, but the request have a great delay to trigger the error signal. And how i define the maximum timeout for request?

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

          You could manually start a QTimer at the same time you make your initial request, which would trigger the "timeout" handling if it is allowed to expire. Then in the slot which handles the finished() signal, you can stop the timer so it never has a chance to expire when things work as expected.

          Software Engineer
          My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

          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