Killtimer, starttimer from another thread



  • Hello,

    I've noticed in my debug output from a program that is seemingly working fine that when accessing an RS-232 device in a worker thread I see a lot of these messages:

    WARNING QObject::killTimer: Timers cannot be stopped from another thread
    WARNING QObject::startTimer: Timers cannot be started from another thread
    

    In the device code in question I don't remember doing any QTimer related stuff. I do use a QElapsedTimer within the object to track how long RS-232 responses take and allow for timeouts.

    Is QElapsedTimer somehow dependent upon QObject::timer?

    What generally does these messages indicate?

    On sort of the same subject I need the code for this device to be usable in two general ways:

    1. Called using buttons from a diagnostic dialog. In this case the object is totally foreground and when a button is pressed I need to send a command and wait for and check / display results.

    2. The same object has to be completely usable (same commands/responses) from a worker thread running an automated process. Obviously not at the same time as #1.

    What generally is the best way to support timeout loops when working threaded versus foreground?

    In the old Delphi days I did something like below and just made sure the thread passed in a null to the GetResponse() function. How should this kind of thing be done in Qt?

    function GetResponse( Caller:TObject; Timeout:integer )
    begin
        while( timer.elapsed < Timeout )
        begin
            if( ReadAll()=false )
               begin
                    if( Caller ) then
                         Application.ProcessMessages
                    else
                         sleep(5);
               end;
         end;
    end;

  • Qt Champions 2016

    @SysTech

    Hello,

    Is QElapsedTimer somehow dependent upon QObject::timer?

    I shouldn't think so.

    What generally does these messages indicate?

    Someone called one of the above functions from another thread, however without a bit of code or any idea of what's done it hard to tell why this might be happening.

    What generally is the best way to support timeout loops when working threaded versus foreground?

    If I'm understanding the question correctly, you could just start a timer - QTimer object and connect whatever you wish to its timeout signal. Note, though, that the timer is not precise.

    Kind regards.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.