I have a global variable that i set on a cpp file on my qt project. I want to check this variable in every 100ms for 5 second and if the variable is 0 after 5 seconds I want to create a message box. Here is the sample of my code:
db.cpp:
if(case){
g_clickedObj.readFlag = 1 ;
}
else{
g_clickedObj.readFlag = 0 ;
}
mainwindow.cpp
this->tmr = new QTimer();
connect(this->tmr,SIGNAL(timeout()),this,SLOT(callSearchMachine()));
tmr->start(5000);
Option 1: Use a timer with 100ms interval to check global variable, hold a member variable for counting how many times timer slot called. When slot called 5000/100=50 times, stop timer and create message box if necessary.
void MyClass::onTimeout(){
// check variable
// increment counter
// check if counter reached 5000/100
// if so stop timer and create message box
}
Option 2: Use two counters(one with 100ms interval, other with 5000ms) which has two different slots. Start both counters at same time. Let 100ms timer's slot check global variable, let 5000ms timer's slot stop both timers and check global variable, create message box if necessary.