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. Prevent events from accumulating...

Prevent events from accumulating...

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 2.5k 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.
  • D Offline
    D Offline
    drhalftone
    wrote on last edited by
    #1

    I have a high speed camera, and I want to take the incoming video and send it to an OpenGL context as a texture. With each new frame, the code over writes the previous texture buffer. Sadly, Qt can't quite keep up with all these events. So I'm calling the update() event fewer times than I'm uploading textures. So this texture upload is a slot inside my custom QGLWidget, and I want to detect incoming events before calling this slot.

    From my reading, update events are filtered by Qt such that multiple events don't build up in the event queue. Does anyone know how to mimic that behavior for other slots so that I never have more than one event sitting in the queue at any one time?

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi, first of all events and slots are two very different mechanisms. You don't "call" events. You can post an event and Qt will call an event handler and aggregate if they stack up. A call to update() is not the same as posting event. It's a plain function call. There is an event posted somewhere underneath, but that's an implementation detail. Another thing is that for QGLWidget you should call updateGL() when you want to draw, not update() which might involve widget geometry refresh, size hints calculation etc. and can be potentially slower.

      As for slots, if threading is not involved, the default connection for signals/slots is a DirectConnection, which is no more expensive than a function call so it should be quite fast.
      So please clarify what you're doing. There might be an easy solution, we just need to be on the same page.

      In any case there's little point in updating a texture if you can't display it fast enough. It just unnecessarily drains resources. Maybe the problem you see is related to v-sync and not Qt event handling? Maybe you block without realizing it.
      A gut feeling is that you're calling update(), which blocks until next v-sync.
      I think what you should be doing is either disable v-sync via GL extension (but why would you want to do that?) or draw only when you actually need to.

      1 Reply Last reply
      0
      • D Offline
        D Offline
        drhalftone
        wrote on last edited by
        #3

        Let me start over. I have two QObjects running in two different threads. One object emits signals a lot. The other receives the signals and processes it. But each call takes a while. Perhaps object 1 emits signals at 5 to 10 times the rate the object 2 can process them. I'd like to simply skip all accumulated signals and just jump to the most recent signal. How can I tell object 2 to ignore all but the last signal?

        1 Reply Last reply
        0
        • D Offline
          D Offline
          drhalftone
          wrote on last edited by
          #4

          Also, updateGL() gives the OpenGL widget priority over all other Qt events. Updating the QGLWidget locks up the rest of the interface. Update() skips a lot of widget refreshes and is then free to answer other QEvents. So the rest of the non-QGLWidget's stay responsive.

          1 Reply Last reply
          0
          • Chris KawaC Offline
            Chris KawaC Offline
            Chris Kawa
            Lifetime Qt Champion
            wrote on last edited by
            #5

            You can't really skip signals, but there are few ways to have the same effect.

            One would be to set some "dirty flag" eg. a boolean in the slot and start a timer that would "poll" that flag at some constant interval to do the update.

            Similarly you can do the inverse. Whenever you start the update you would set a flag and clear it at the end. If a signal comes in between and the flag is set (i.e. it's still working) you would consider the signal accumulating and skip it.

            1 Reply Last reply
            0

            • Login

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