Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved Q timer Event with timer id

    General and Desktop
    5
    6
    1102
    Loading More Posts
    • 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.
    • qt_ankit_developer
      qt_ankit_developer last edited by

      Dear sir,
      I want to implement a continuous calling for a function from Q Timer::timer Event(QTimerEvent *e) by creating a timer event using QTimerEvent::QTimerEvent(int timerId) that calls a function continuous in a specific time.
      so please help me to create a timer event for continuous calling of a particular function.

      J.Hilk 1 Reply Last reply Reply Quote 0
      • sierdzio
        sierdzio Moderators last edited by

        @qt_ankit_developer said in Q timer Event with timer id:

        to create a timer event for continuous calling of a particular function.

        Why do you want it to be a QTimerEvent?

        It's easier to just use QTimer and connect it to a slot.

        (Z(:^

        1 Reply Last reply Reply Quote 1
        • J.Hilk
          J.Hilk Moderators @qt_ankit_developer last edited by J.Hilk

          @qt_ankit_developer
          even so @sierdzio is correct, a QTimer instance would be easier. Here is how you would do it via QTimerEvent:

          void myClass::startMyTimerEvent()
          {
              if (m_timerId == -1)
                  m_timerId = startTimer(m_Timeout);
          }
           
          void myClass:: stopMyTimerEvent()
          {
              if (m_timerId != -1)
                  killTimer(m_timerId);
              m_timerId = -1;
          }
          
          void myClass::timerEvent(QTimerEvent *event)
          {
             if(event->timerId() == m_timerId) {
                 //do Stufff
                 ....
                callMyFunction();
             }
          }
          

          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct

          Qt Needs YOUR vote: https://bugreports.qt.io/browse/QTQAINFRA-4121


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          1 Reply Last reply Reply Quote 5
          • qt_ankit_developer
            qt_ankit_developer last edited by

            how can i call different event with different timer ids

            1 Reply Last reply Reply Quote 0
            • dheerendra
              dheerendra Qt Champions 2022 last edited by

              There is nothing like calling different event with different timer ids. As @J-Hilk suggested with example, you start multiple timers. Each timer started will have timer ids. When the timer expires, it will call handler timerEvent(...). Inside the handler you need to check the appropriate timerIds and call the different eventHandler based on your requirement.

              As @sierdzio suggested, you can consider using QTimer itself.

              Dheerendra
              @Community Service
              Certified Qt Specialist
              http://www.pthinks.com

              1 Reply Last reply Reply Quote 5
              • SGaist
                SGaist Lifetime Qt Champion last edited by

                Hi,

                You can build a map with the timer ids and method to call and use that in timerEvent to call the right function.

                However, a list of QTimer might be easier to handle.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply Reply Quote 2
                • First post
                  Last post