Results 1 to 5 of 5

Thread: QThread and QTimer

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2008
    Posts
    16
    Qt products
    Qt4
    Platforms
    Windows

    Default QThread and QTimer

    Hi there,

    i have a QTimer conflict within a ClassA inheriting from QThread. ClassA has a massive data processing routine, which we call from the QThread::run() in order to let it run with the Qt::LowPriority. This works fine. ClassA has a single instance during the whole runtime of the application.


    Qt Code:
    1. class ClassA : QThread
    2. {
    3. public:
    4. ClassA();
    5. ~ClassA();
    6. InitGUI();
    7. focusHasLeft();
    8. focusHasCome();
    9.  
    10. protected slots:
    11. void refreshTimerSlot(); // this eventually starts the thread for reload of data
    12. threadFinished(); // this slot is connected to the "thread is finished" signal
    13.  
    14. private:
    15. //start the thread with low priority.
    16. startThread();
    17.  
    18. // QThread
    19. void run(void); // this calls massiveDataReloadRoutine()
    20. void massiveDatareloadRoutine();
    21.  
    22. QTimer refreshTimer;
    23. }
    To copy to clipboard, switch view to plain text mode 

    ClassA has a refresh timer which is used update the GUI periodically. This timer is in conflict with the QThread giving the message

    "QObject::startTimer: timers can not be started from another thread"
    inside the debug window. As a result, I can not start and stop the timer, and it runs all the time. The timer slot is being called without a problem.



    But the problem is, if a change focus from the view i want to stop the timer so that the updates should not steal processing time.

    In order to to stop the timer i have tried:

    1) to stop the timer in ClassA::run() -> did not work
    2) to stop the timer in ClassA::focusHasLeft() -> did not work
    3) to stop the timer in ClassA::threafFinished() -> did not work

    What is wrong?
    Last edited by jpn; 1st May 2009 at 11:02. Reason: missing [code] tags

Similar Threads

  1. Replies: 8
    Last Post: 27th March 2013, 11:51
  2. QTimer in QThread doesn't start or timeout
    By Boron in forum Qt Programming
    Replies: 9
    Last Post: 21st October 2011, 13:51
  3. QThread & QTimer
    By hosseinyounesi in forum Qt Programming
    Replies: 5
    Last Post: 13th April 2009, 08:22
  4. QTimer and QThread in Qtopia 4.2.0
    By mellibra in forum Qt for Embedded and Mobile
    Replies: 3
    Last Post: 25th October 2007, 08:26
  5. QTimer and QThread
    By TheKedge in forum Qt Programming
    Replies: 4
    Last Post: 21st September 2006, 14:52

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.