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. QObject timer events happening in reverse order
Forum Updated to NodeBB v4.3 + New Features

QObject timer events happening in reverse order

Scheduled Pinned Locked Moved Unsolved General and Desktop
timerevent
6 Posts 4 Posters 1.1k Views 1 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.
  • P Offline
    P Offline
    pderocco
    wrote on last edited by
    #1

    If I create a slew of timers, all with the same interval, and their scheduled time ends up being on the same tick of whatever clock they are scheduled against, they fire their events in the reverse order. Doesn't this seem Very Wrong? Does anyone know a way around this? I'm using 5.12 RC2 on Windows.

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

      what is the way around are you looking for ? Are you using timerEvent(..) or QTimer ?.

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

      1 Reply Last reply
      0
      • P pderocco

        If I create a slew of timers, all with the same interval, and their scheduled time ends up being on the same tick of whatever clock they are scheduled against, they fire their events in the reverse order. Doesn't this seem Very Wrong? Does anyone know a way around this? I'm using 5.12 RC2 on Windows.

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @pderocco I actually wouldn't expect any specific order if all timers fire at the same time. Why is the order important to you? And why do you have several timers with same interval?

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        6
        • P Offline
          P Offline
          pderocco
          wrote on last edited by
          #4

          I'm using QObject::startTimer(), and defining my own virtual QOBJECT::timerEvent(). They're part of a simple system by which I can launch a function to be called in a certain amount of time. I'm trying to simulate a comm link that has a delay, so I want things to "get there" after a certain amount of time, but certainly in the same order that I sent them. The easiest way to implement this is to create a timer for each message I send, and kill the timer when it arrives. I catalog the function to be called as a numbered property of a common schedule object, indexed by the timer id, and delete the property after calling the function in timerEvent. It all works just peachy, except that it appears that when they are scheduled on the same timer tick, they are perversely pushed onto a stack rather than into a queue.

          Since they just released the official 5.12, I'm going to install that and see if there's any difference.

          P W 2 Replies Last reply
          0
          • P pderocco

            I'm using QObject::startTimer(), and defining my own virtual QOBJECT::timerEvent(). They're part of a simple system by which I can launch a function to be called in a certain amount of time. I'm trying to simulate a comm link that has a delay, so I want things to "get there" after a certain amount of time, but certainly in the same order that I sent them. The easiest way to implement this is to create a timer for each message I send, and kill the timer when it arrives. I catalog the function to be called as a numbered property of a common schedule object, indexed by the timer id, and delete the property after calling the function in timerEvent. It all works just peachy, except that it appears that when they are scheduled on the same timer tick, they are perversely pushed onto a stack rather than into a queue.

            Since they just released the official 5.12, I'm going to install that and see if there's any difference.

            P Offline
            P Offline
            pderocco
            wrote on last edited by
            #5

            An update: Unsurprisingly, 5.12 doesn't change anything.

            I notice, though, that if I set the delay to zero, so that each timer merely fires as soon as the event loop is idle, they are all enqueued in the correct order, and the messages arrive in order. But of course, there is no programmable delay.

            I wound up writing about a page of JS, along with a small C++ interface to the QObject timer, that uses a sparse array to associate a target time with a list of functions to call, and a single timer to signal an event on the earliest tick listed in the schedule. It works, but it is unwieldy and not nearly as efficient as just creating a timer per message. But it does let me control the order of things on each tick.

            1 Reply Last reply
            0
            • P pderocco

              I'm using QObject::startTimer(), and defining my own virtual QOBJECT::timerEvent(). They're part of a simple system by which I can launch a function to be called in a certain amount of time. I'm trying to simulate a comm link that has a delay, so I want things to "get there" after a certain amount of time, but certainly in the same order that I sent them. The easiest way to implement this is to create a timer for each message I send, and kill the timer when it arrives. I catalog the function to be called as a numbered property of a common schedule object, indexed by the timer id, and delete the property after calling the function in timerEvent. It all works just peachy, except that it appears that when they are scheduled on the same timer tick, they are perversely pushed onto a stack rather than into a queue.

              Since they just released the official 5.12, I'm going to install that and see if there's any difference.

              W Offline
              W Offline
              wrosecrans
              wrote on last edited by
              #6

              @pderocco

              Packets arriving out of order is a pretty accurate simulation of commlinks over the Internet. But if you want ordered serialization, you'll need to do that yourself. Put the messages in a queue, and pop the head whenever it's delivery time is less than the current time.

              1 Reply Last reply
              3

              • Login

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