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. Killtimer, starttimer from another thread
Forum Updated to NodeBB v4.3 + New Features

Killtimer, starttimer from another thread

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 1.7k Views 1 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
    SysTech
    wrote on last edited by
    #1

    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;
    
    kshegunovK 1 Reply Last reply
    0
    • S SysTech

      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;
      
      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by kshegunov
      #2

      @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.

      Read and abide by the Qt Code of Conduct

      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