Hy
I am writing my first Qt program and am now experiencing problems:
QObject :: killTimer: timers cannot be stopped from another thread
QObject :: startTimer: timers cannot be started from another thread
My program will communicate with the CANOpen bus because I use the Canfestival Stack . Canfestival will work with callback methods. To detect a timeout in communication, I set up a timer function (kind of like a watchdog). My timer package consists of the tmr module, the TimerForFWUpgrade module, and the SingleTimer module. The tmr module was originally programmed in C, so the static methods of TimerForFWUpgrade will interact with it. The tmr module will be part of the C firmware update package.
The timer will work as follows. Before sending the message, I will call the TMR_Set method. Then, in my idle program cycle with TMR_IsElapsed, we check the lower flow of the timer. If TMR_IsElapsed, I will do error handling. As you can see, the TMR_Set method will be called continuously and run QTimer again and again.
The above errors appear if I run my program. Can you tell me if my concept can work? Why do these errors appear? Should I use additional threads (QThread) for the main thread?
thanks
Matt
Startup and wait loop:
void run { // start communicate with callbacks where TMR_Set is set continously ... while(TMR_IsElapsed(TMR_NBR_CFU) != 1); // if TMR_IsElapsed check for errorhandling .... }
Tmr module (interface to program C):
extern "C" { void TMR_Set(UINT8 tmrnbr, UINT32 time) { TimerForFWUpgrade::set(tmrnbr, time); } INT8 TMR_IsElapsed(UINT8 tmrnbr) { return TimerForFWUpgrade::isElapsed(tmrnbr); } }
TimerForFWUpgrade module:
SingleTimer* TimerForFWUpgrade::singleTimer[NR_OF_TIMERS]; TimerForFWUpgrade::TimerForFWUpgrade(QObject* parent) { for(unsigned char i = 0; i < NR_OF_TIMERS; i++) { singleTimer[i] = new SingleTimer(parent); } } //static void TimerForFWUpgrade::set(unsigned char tmrnbr, unsigned int time) { if(tmrnbr < NR_OF_TIMERS) { time *= TimerForFWUpgrade::timeBase; singleTimer[tmrnbr]->set(time); } } //static char TimerForFWUpgrade::isElapsed(unsigned char tmrnbr) { if(true == singleTimer[tmrnbr]->isElapsed()) { return 1; } else { return 0; } }
SingleTimer Module:
SingleTimer::SingleTimer(QObject* parent) : QObject(parent), pTime(new QTimer(this)), myElapsed(true) { connect(pTime, SIGNAL(timeout()), this, SLOT(slot_setElapsed())); pTime->setTimerType(Qt::PreciseTimer); pTime->setSingleShot(true); } void SingleTimer::set(unsigned int time) { myElapsed = false; pTime->start(time); } bool SingleTimer::isElapsed() { QCoreApplication::processEvents(); return myElapsed; } void SingleTimer::slot_setElapsed() { myElapsed = true; }