Results 1 to 15 of 15

Thread: QThread and QEventLoop - Idle Processing

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #3
    Join Date
    Aug 2007
    Posts
    14
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QThread and QEventLoop - Idle Processing

    Thank you! That was exactly what I was looking for. It just so happens that I stumbled upon a similar example right before I saw your post. It had suspend function to stop the timer, which is pretty neat. If anyone's interested:

    Qt Code:
    1. class MyThreadObject : public QObject {
    2. QTimer myTimer;
    3.  
    4. MyThreadObject() {
    5. connect( &myTimer, timeout(), this, onTimeOut());
    6. }
    7.  
    8. slot onSuspendThread() {
    9. myTimer.stop();
    10. }
    11.  
    12. slot onResumeThread() {
    13. myTimer.start(0);
    14. }
    15.  
    16. private slot onTimeOut() {
    17. // do a few comutation steps.
    18. // Should return "quickly" to the event loop
    19. }
    20.  
    21. }
    22.  
    23.  
    24. class MyThread : public QThread {
    25. slot MyThread:run() {
    26. MyThreadObject threadObject; //=> the threadObject affinity is the thread
    27. // here, connect the appropriate signals to the appropriate slots
    28.  
    29. threadObject.onResumeThread();
    30. exec();
    31. }
    32.  
    33. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by kloffy; 25th February 2008 at 22:56.

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.