I am communicating with a remote device in qt, and sometimes the remote device is not answering. Therefore I implemented a timer which should notify the function readData() which is usually called when the device answers:
int timerID;
void stepperMworker::start_timer()
{
this->timerID = startTimer(TIME_OUT);
}
void stepperMworker::readData(QString data)
{
killTimer(this->timerID);
//Process data
}
void stepperMworker::timerEvent(QTimerEvent *event)
{
killTimer(this->timerID);
this->readData(QString::number(-1));
}
The idea was that either readData() is called first from the receiving signal from external, and then stops the timer, or the timer itself signalizes the readData()-function after TIME_OUT milliseconds that the external device is not responding. Nevertheless sometimes I get the error Error: timer id 2 is not valid for object 0x98f270 (stepperMworker, ), timer has not been killed. How can I determine if the current timerID is not valid?