sivrisinek
29th April 2009, 17:09
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.
class ClassA : QThread
{
public:
ClassA();
~ClassA();
InitGUI();
focusHasLeft();
focusHasCome();
protected slots:
void refreshTimerSlot(); // this eventually starts the thread for reload of data
threadFinished(); // this slot is connected to the "thread is finished" signal
private:
//start the thread with low priority.
startThread();
// QThread
void run(void); // this calls massiveDataReloadRoutine()
void massiveDatareloadRoutine();
QTimer refreshTimer;
}
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?
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.
class ClassA : QThread
{
public:
ClassA();
~ClassA();
InitGUI();
focusHasLeft();
focusHasCome();
protected slots:
void refreshTimerSlot(); // this eventually starts the thread for reload of data
threadFinished(); // this slot is connected to the "thread is finished" signal
private:
//start the thread with low priority.
startThread();
// QThread
void run(void); // this calls massiveDataReloadRoutine()
void massiveDatareloadRoutine();
QTimer refreshTimer;
}
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?