Qt Forum

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

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    QNetworkAccessManager timeout

    General and Desktop
    3
    4
    5817
    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
      fronald last edited by

      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 Reply Quote 0
      • K
        koahnig last edited by

        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 Reply Quote 0
        • F
          fronald last edited by

          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 Reply Quote 0
          • M
            mlong last edited by

            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 Reply Quote 0
            • First post
              Last post