Qt Forum

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

    QTimer singleShot resolution

    General and Desktop
    1
    1
    717
    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.
    • S
      sting last edited by

      I am building a networked event controled application. The events are very simple:

      Client sents a request to a server;
      Server gets the request and sends a response back to the client.

      It works well, but probably not perfect. The problem is I want to use QTimer single shot events to know if I don't get a response back within a specific time, it is pretty big, so the client knows when it should go into the devcon 3 state :).

      In the class constructor I have:
      @
      cmdTimer = new QTimer();
      cmdTimer->setSingleShot(true);
      connect(cmdTimer, SIGNAL(timeout()), this, SLOT(timeout()));
      connect(this, SIGNAL(stopTimer(int)), cmdTimer, SLOT(stop()));
      @

      I start the singleShot timer as follows:
      @
      // just before the request
      cmdTimer->singleShot(100, this, SLOT(timeout()));
      sendRequest();
      @

      I stop the timer if the event comes in as follows:
      @
      emit stopTimer();
      @

      If the response comes back before the timeout is fired all is good, the timer is stoped and I never get the timeout. I am trying to ensure it works correctly so I have the server sleep for a period twice as long as the singleshot request and I expect to get a timeout with each request.

      I get the first couple of timeouts correctly, but after a few they stop for 4 commands and after the 4th command I get the 4 outstanding timeouts. Also, could this be because I am still debugging the app on a single machine?

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