Results 1 to 9 of 9

Thread: Checking for gui events

  1. #1
    Join Date
    Jan 2010
    Posts
    7
    Thanked 1 Time in 1 Post

    Default Checking for gui events

    I have an app that is displaying full HD video at 60fps.
    This is maxing out the CPU and since all the display has to be done in the gui thread it is missing any mouse or keyboard events.

    I tried putting a QApplication:rocessEvents() in the paint event but this halves my frame rate. Other than hacks - like calling this every 60frames and living with the glitch, is there a way of quickly checking if any key/mouse event is pending?

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Checking for gui events

    The proper way is not doing in on the CPU, but the GPU (OpenGL)
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Jan 2010
    Posts
    7
    Thanked 1 Time in 1 Post

    Default Re: Checking for gui events

    I am doing it in openGL thats the problem!
    Painting a QImage in paintEvent is too slow so I'm doing a full screen openGL texture in paintGL.
    Repaint with a QPaintEvent does seem to check mouse/key events but paintGL doesn't

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Checking for gui events

    OpenGL doesn't nesseraly runs on the GPU!

    In any case since you are using OpenGL you can do the rendering in a worker thread, releasing the GUI thread to be bored with mouse events.
    Just take care:
    Threading

    It is possible to render into a QGLWidget from another thread, but it requires that all access to the GL context is safe guarded. The Qt GUI thread will try to use the context in resizeEvent and paintEvent, so in order for threaded rendering using a GL widget to work, these functions need to be intercepted in the GUI thread and handled accordingly in the application.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Checking for gui events

    Quote Originally Posted by mgb View Post
    Repaint with a QPaintEvent does seem to check mouse/key events but paintGL doesn't
    What exactly do you mean by "does seem to check mouse/key events"? What does painting have to do with handling input events? Aren't you running an endless loop somewhere?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    Jan 2010
    Posts
    7
    Thanked 1 Time in 1 Post

    Default Re: Checking for gui events

    A new set of 1920x1080x3 pixels arrives at 60hz, I have to get the block of memory and throw it at the screen.
    If I override paintEvent() and use Qpainter->drawImage() or Qpixmap::fromImage I manage about 30-40fps.
    But at least I have some mouse/keyboard response.

    If I use paintGL and draw a full screen texture quad I can get 60fps but any mouse, keyboard events are ignored - unless I explicitly call QApp:rocessEvents() periodically.

    Being able to draw openGL in a non-gui thread might be a usefull approach - I didn't know that was possible.
    My problem was that input events have to be processed in the gui thread but it is the gui thread I am maxing out trying to push that many pixels to the screen.

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Checking for gui events

    How exactly are you trying to achieve 60Hz refresh rate? What makes your window refresh?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #8
    Join Date
    Jan 2010
    Posts
    7
    Thanked 1 Time in 1 Post

    Default Re: Checking for gui events

    The image data arrives from the camera at 60 fps in a separate thread.
    I emit() an event when each new frame is buffered and in the gui thread hook that event to repaint.

    I also wrap the repaint in a QMutex because if it can't keep up with 60hz you don't want two QPainters running at once.

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Checking for gui events

    And what if something else calls your paint event? This is not a good approach.

    Have a variable that will keep the current frame to be displayed. Protect it with a mutex if you wish to feed the frames from a separate thread. Setup a timer that will fire either 60 times per second or every time the application has time to update the widget (which is done by setting the timeout to 0). Have the timer call update() on your widget. In the paint routine read the image data from the variable you have and render it. The variable keeps the current frame to be rendered. If it happens that the application can't keep up the pace, frames will be dropped by overwriting the current frame with a new one. Definitely don't put any mutexes in the paint event unless you have to. This all will make sure all your input events get processed on time.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. checking user presence
    By Tomasz in forum Newbie
    Replies: 1
    Last Post: 3rd September 2010, 13:19
  2. Checking network availability
    By fullmetalcoder in forum Qt Programming
    Replies: 2
    Last Post: 10th March 2008, 19:23
  3. Checking progress efficiently | C++
    By Backslash in forum General Programming
    Replies: 3
    Last Post: 23rd February 2008, 21:58
  4. Checking if bad pointer?
    By steg90 in forum Qt Programming
    Replies: 4
    Last Post: 22nd May 2007, 09:06
  5. checking for null
    By drkbkr in forum General Programming
    Replies: 6
    Last Post: 13th March 2006, 21:54

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.