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
Forum Updated to NodeBB v4.3 + New Features

Q timer Event with timer id

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 5 Posters 1.7k Views 2 Watching
  • 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.
  • Q Offline
    Q Offline
    qt_ankit_developer
    wrote on 12 Nov 2018, 08:50 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 1 Reply Last reply 12 Nov 2018, 09:24
    0
    • S Offline
      S Offline
      sierdzio
      Moderators
      wrote on 12 Nov 2018, 09:07 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
      • Q qt_ankit_developer
        12 Nov 2018, 08:50

        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 Offline
        J Offline
        J.Hilk
        Moderators
        wrote on 12 Nov 2018, 09:24 last edited by J.Hilk 11 Dec 2018, 09:26
        #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
        • Q Offline
          Q Offline
          qt_ankit_developer
          wrote on 14 Nov 2018, 11:42 last edited by
          #4

          how can i call different event with different timer ids

          1 Reply Last reply
          0
          • D Offline
            D Offline
            dheerendra
            Qt Champions 2022
            wrote on 14 Nov 2018, 12:39 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
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 14 Nov 2018, 21:47 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

              5/6

              14 Nov 2018, 12:39

              • Login

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