Important: Please read the 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()));
    readSensor();   //added to call on boot itself, can be removed
    void HomePage::readSensor(void) {
       qDebug() << "Read Sensor triggerred at " <<QDateTime::currentDateTime().toString();
       //DO my actions

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

  • Lifetime Qt Champion

    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

  • Lifetime Qt Champion

    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