Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QTimer timeout triggered for multiple times?

QTimer timeout triggered for multiple times?

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 1.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Kanni1303K Offline
    Kanni1303K Offline
    Kanni1303
    wrote on last edited by
    #1

    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

    Character make's Gentlemen, not appearance.
    --Vivekananda

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      Kanni1303K 1 Reply Last reply
      4
      • Kanni1303K Offline
        Kanni1303K Offline
        Kanni1303
        wrote on last edited by
        #3

        that sleep is conversion time for sensor to process the data

        Character make's Gentlemen, not appearance.
        --Vivekananda

        1 Reply Last reply
        0
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Please provide a minimal example - your current code doesn't look wrong except the (still unanswered) question for the double connect.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          1
          • Christian EhrlicherC Christian Ehrlicher

            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.

            Kanni1303K Offline
            Kanni1303K Offline
            Kanni1303
            wrote on last edited by
            #5

            @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

            Character make's Gentlemen, not appearance.
            --Vivekananda

            1 Reply Last reply
            1

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved