Page 2 of 2 FirstFirst 12
Results 21 to 33 of 33

Thread: QObject::killTimers() warning after timer stopped from its own thread

  1. #21
    Join Date
    Oct 2012
    Location
    The land of pain (NY)
    Posts
    99
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Windows Android
    Thanks
    7
    Thanked 3 Times in 2 Posts

    Default Re: QObject::killTimers() warning after timer stopped from its own thread

    I've compiled a complete application with the changes that have been posted in this thread. It's possible as you have suggested that the app is attempting to stop the timer before the thread completes.

    test app attached here ->> workerTest.zip

  2. #22
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: QObject::killTimers() warning after timer stopped from its own thread

    Does the code you posted still contain the bug? I'm not getting any warnings.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #23
    Join Date
    Oct 2012
    Location
    The land of pain (NY)
    Posts
    99
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Windows Android
    Thanks
    7
    Thanked 3 Times in 2 Posts

    Default Re: QObject::killTimers() warning after timer stopped from its own thread

    Quote Originally Posted by wysota View Post
    Does the code you posted still contain the bug? I'm not getting any warnings.
    The code example I posted still reports the warning message. Are you able to compile and run it? I am using 4.8.4 with Win SDK 7.1 compiler under Creator 2.6

  4. #24
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: QObject::killTimers() warning after timer stopped from its own thread

    I'm not getting any warnings. I use Qt 4.8.3 x64 Linux. Same output with Qt 5.0 RC2.

    $ ./FlashWizard
    Main thread: QThread(0xcde710)
    Worker Object Thread Id: QThread(0x7ffff75eff00)
    Now using thread: QThread(0x7ffff75eff00)
    1
    2
    3
    ...
    97
    98
    99
    100
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #25
    Join Date
    Oct 2012
    Location
    The land of pain (NY)
    Posts
    99
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Windows Android
    Thanks
    7
    Thanked 3 Times in 2 Posts

    Default Re: QObject::killTimers() warning after timer stopped from its own thread

    Quote Originally Posted by wysota View Post
    I'm not getting any warnings. I use Qt 4.8.3 x64 Linux. Same output with Qt 5.0 RC2.
    Oh I guess the problem wasn't fully realized. It's only when you click the cancel button before the loop finishes that the message is shown - sorry. I should have re-iterated that. I though that was evident within the thread.

  6. #26
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: QObject::killTimers() warning after timer stopped from its own thread

    Still, no warning

    An idea: maybe you shouldn't be using a thread at all? What do you need it for?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #27
    Join Date
    Oct 2012
    Location
    The land of pain (NY)
    Posts
    99
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Windows Android
    Thanks
    7
    Thanked 3 Times in 2 Posts

    Default Re: QObject::killTimers() warning after timer stopped from its own thread

    Quote Originally Posted by wysota View Post
    Still, no warning

    An idea: maybe you shouldn't be using a thread at all? What do you need it for?
    So let me understand. You run this app. Before the count gets to 100, hit the brakes with the Cancel button. You're telling me no message like "QObject::killTimer: timers cannot be stopped from another thread"?

    This is a stripped out app that is used as a prototype for use with a hardware DLL. That library has functions that are called for each timer tick and have to perform tasks in the background that would otherwise tie up the UI. I created this to perform a task (a loop counter in this case) and update a progress bar. I find it incredible that this test app loaded on a host PC and on a virtual machine and on my own laptop all perform exactly the same - that is, the killTimer warning is displayed in the debug window after the Cancel button is clicked and before the counter gets to 100, except for you.

    I read your article on keeping the UI responsive as well as general considerations when making calls to hardware while updating a UI with background workers. I feel that background tasks belong in another thread so as to keep the UI responsive. That's my reason for this prototype. That's pretty much boilerplate practice. I don't have a Linux distro prepared for testing on there.


  8. #28
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: QObject::killTimers() warning after timer stopped from its own thread

    Quote Originally Posted by astodolski View Post
    So let me understand. You run this app. Before the count gets to 100, hit the brakes with the Cancel button. You're telling me no message like "QObject::killTimer: timers cannot be stopped from another thread"?
    Nope. The last thing I get is a number. Maybe I should wait an hour for the message to appear

    That library has functions that are called for each timer tick and have to perform tasks in the background that would otherwise tie up the UI.
    It doesn't yet mean you need to do any threading.

    I created this to perform a task (a loop counter in this case) and update a progress bar. I find it incredible that this test app loaded on a host PC and on a virtual machine and on my own laptop all perform exactly the same - that is, the killTimer warning is displayed in the debug window after the Cancel button is clicked and before the counter gets to 100, except for you.
    Do you want me to shoot a video? Maybe the thing is that you're using Windows and I'm not (however I doubt it).

    I feel that background tasks belong in another thread so as to keep the UI responsive.
    You can always delegate the task to an external process and talk to it using QProcess or QLocalSocket. However I still think threading is not required here, especially if it's a source of some problems. Nevertheless I think the code you have is easy to fix to work within a thread. Maybe you just need to restructure the code.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #29
    Join Date
    Oct 2012
    Location
    The land of pain (NY)
    Posts
    99
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Windows Android
    Thanks
    7
    Thanked 3 Times in 2 Posts

    Default Re: QObject::killTimers() warning after timer stopped from its own thread

    Quote Originally Posted by wysota View Post
    You can always delegate the task to an external process and talk to it using QProcess or QLocalSocket.
    My DLL is only functions in a library. It is not an external program which is what QProcess takes care of. QLocalSocket would be helpful but not really what I need.

    Your article even supports threads for external libraries http://doc.qt.digia.com/qq/qq27-resp...gaworkerthread

    However I still think threading is not required here, especially if it's a source of some problems.
    But not necessarily a Qt bug.

    Nevertheless I think the code you have is easy to fix to work within a thread. Maybe you just need to restructure the code.
    I still think this is viable if I can get the thread stopped properly. That is what was previously suspected.
    Last edited by astodolski; 20th December 2012 at 01:00.

  10. #30
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: QObject::killTimers() warning after timer stopped from its own thread

    Quote Originally Posted by astodolski View Post
    I still think this is viable if I can get the thread stopped properly. That is what was previously suspected.
    A possible fix is very easy. Use QObject::startTimer() and QObject::killTimer() instead of an external QTimer instance.

    Qt Code:
    1. void MyWorker::start() { m_tid = startTimer(100); } // slot
    2. void MyWorker::stop() { killTimer(m_tid); } // slot
    3. void MyWorker::timerEvent(QTimerEvent *ev) {
    4. if(ev->timerId() == m_tid) doWork();
    5. else QObject::timerEvent(ev);
    6. }
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. #31
    Join Date
    Oct 2012
    Location
    The land of pain (NY)
    Posts
    99
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Windows Android
    Thanks
    7
    Thanked 3 Times in 2 Posts

    Unhappy Re: QObject::killTimers() warning after timer stopped from its own thread

    Quote Originally Posted by wysota View Post
    A possible fix is very easy. Use QObject::startTimer() and QObject::killTimer() instead of an external QTimer instance.

    Qt Code:
    1. void MyWorker::start() { m_tid = startTimer(100); } // slot
    2. void MyWorker::stop() { killTimer(m_tid); } // slot
    3. void MyWorker::timerEvent(QTimerEvent *ev) {
    4. if(ev->timerId() == m_tid) doWork();
    5. else QObject::timerEvent(ev);
    6. }
    To copy to clipboard, switch view to plain text mode 
    Thanks anyway. This didn't change anything. I changed the slots in the worker as shown. No improvement. Perhaps another viewer running Windows can try the sample I posted with the changes mentioned since it seems to be Windows only related.

  12. #32
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: QObject::killTimers() warning after timer stopped from its own thread

    You shouldn't be getting that error with the code I posted. Unless maybe you delete the worker object from within a wrong thread (if it gets deleted at all). Try cleaning and rebuilding the project from scratch.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  13. #33
    Join Date
    Oct 2012
    Location
    The land of pain (NY)
    Posts
    99
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Windows Android
    Thanks
    7
    Thanked 3 Times in 2 Posts

    Default Re: QObject::killTimers() warning after timer stopped from its own thread

    Quote Originally Posted by wysota View Post
    You shouldn't be getting that error with the code I posted. Unless maybe you delete the worker object from within a wrong thread (if it gets deleted at all). Try cleaning and rebuilding the project from scratch.
    Done that. Still as is. Should I post the updated project?

    BTW for reference, it seems as others have experienced the same on Windows though I dont know any further detail.
    http://qt-project.org/forums/viewthread/22916

    I found something that may be helpful.

    With all the current changes, I note that the stop slot gets called twice. The first time through the current thread is the main thread - hence the message. The second time through the current thread is the worker thread.

    In line 957 of qeventdispatcher_win.cpp

    thread() != QThread::currentThread;

    We get here from killTimer which calls unregisterTimer.

    Note that on a Linux system, you may never get to that line of code because it is in a different module altogether.
    Last edited by astodolski; 20th December 2012 at 17:01. Reason: updated contents

Similar Threads

  1. Replies: 1
    Last Post: 29th July 2010, 05:41
  2. QObject::killTimer Warning Messages
    By mclark in forum Qt Programming
    Replies: 7
    Last Post: 11th September 2008, 20:10
  3. how to enable a timer in a non-gui thread?
    By zeopha in forum Qt Programming
    Replies: 3
    Last Post: 5th August 2008, 09:29
  4. Replies: 2
    Last Post: 24th March 2008, 16:59
  5. QObject::moveToThread warning
    By mnemonic_fx in forum Qt Programming
    Replies: 3
    Last Post: 10th August 2007, 22:11

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.