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. Q timer Event with timer id

Q timer Event with timer id

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 5 Posters 1.6k 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.
  • qt_ankit_developerQ Offline
    qt_ankit_developerQ Offline
    qt_ankit_developer
    wrote on last edited by
    #1

    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.HilkJ 1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      @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
      1
      • qt_ankit_developerQ qt_ankit_developer

        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.HilkJ Offline
        J.HilkJ Offline
        J.Hilk
        Moderators
        wrote on last edited by J.Hilk
        #3

        @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


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

        1 Reply Last reply
        5
        • qt_ankit_developerQ Offline
          qt_ankit_developerQ Offline
          qt_ankit_developer
          wrote on last edited by
          #4

          how can i call different event with different timer ids

          1 Reply Last reply
          0
          • dheerendraD Offline
            dheerendraD Offline
            dheerendra
            Qt Champions 2022
            wrote on last edited by
            #5

            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
            5
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              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
              2

              • Login

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