Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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);
     }
    

    0_1557065378655_Screenshot from 2019-05-05 19-16-45.png


  • Qt Champions 2019

    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


  • Qt Champions 2019

    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


Log in to reply