Solved QTimer timeout triggered for multiple times?
-
I'm creating a UI application for Raspberry PI to read data from sensor on definite timeout (5 seconds). Problem is the QTimer timeout slot is called for multiple times
{ //at system init readTempCur = new QTimer(this); connect(readTempCur, SIGNAL(timeout()), this, SLOT(readSensor())); readTempCur->start(SAMPLINGTIME); readSensor(); //added to call on boot itself, can be removed } void HomePage::readSensor(void) { readTempCur->stop(); qDebug() << "Read Sensor triggerred at " <<QDateTime::currentDateTime().toString(); //DO my actions readTempCur->start(SAMPLINGTIME); }
-
Are you sure you don't connect the signal twice?
Also qApp->processEvents() is not needed at all. And doing a sleep inside the main thread isn't a good idea even it's only 2ms but this shouldn't be your current problem. -
that sleep is conversion time for sensor to process the data
-
Please provide a minimal example - your current code doesn't look wrong except the (still unanswered) question for the double connect.
-
@Christian-Ehrlicher Brilliant! thanks, on some random occasion the sysInit() is called for multiple times which reconnected same slot to same signal once again. I hope fixing that will probably fix this one