Results 1 to 6 of 6

Thread: QTimer ->start(0) + OpenGL + resize/move window => crash

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2008
    Posts
    10
    Qt products
    Qt4
    Platforms
    Windows
    Thanked 1 Time in 1 Post

    Wink QTimer ->start(0) + OpenGL + resize/move window => crash

    Hi,

    I've got an issue with OpenGL.
    I've got a QMainWindow (loaded from a .ui), that include a QGLWidget, well in fact an instance of a personnalize class that inherits from QGLWidget, ...

    Actually I'm migrating an SDL+OpenGL application into a QT 4.4 + OpenGL app
    It's kind of a 3D cloud points viewer.

    Ok by now everything works, I see the scene, I can interact with it (keyboard, mouse), but it's not perfect.

    In the first time my idea was to do like in SDL : an infinit while(true) loop.
    I managed to do that with this code in constructor :
    Qt Code:
    1. connect(&qTimerRedraw, SIGNAL(timeout()), this, SLOT(dessiner()));
    2. qTimerRedraw.start(0); // CPU = 100%
    To copy to clipboard, switch view to plain text mode 

    As the comment explains, it's pretty obvious that one core is going to be at 100% because of the QTimer interval set to 0. And I really don't care if so, because I know how to slow down the framerate in order to reduce the CPU usage. (I could also see the FPS in live).
    It's great, very fluid with key events (stay pressed, release, ...).

    The problem is that : my application is sometimes crashing when I move the window or when I resize it. Precisely, the crash occurs when i release the mouse button. Why does this crash appears errraticaly ?
    I tried to QDebug ResizeGL() without success.

    After I realize the bug was due to the infinite signal<->slot loop, I had a second idea : pause the timer during the "work time" :
    Qt Code:
    1. void gldrawer::paintGL()
    2. {
    3. qTimerRedraw.stop(0); // wait before the end
    4.  
    5. // paint job ... (heavy work)
    6.  
    7. qTimerRedraw.start(0); // restart
    8. }
    To copy to clipboard, switch view to plain text mode 

    This might be a good idea with a long "work time" but it doesn't resolve my issue.

    My third idea was a different approch : during my research I discover that lots of example works in another way to handle user interaction. The scene is refreshed only when a user interaction leads to a repaint (keyboard or mouse event typically).
    That is a very good idea because you do not need to do an infinite loop (100%CPU) so it was solving my problem in 2 ways :
    -no loop => no crash when moving or resizing
    -my application does not have animations, it's only when the user interact that I have to redraw

    So I made modifications to my code, but now there is another problem : keys events.
    -I can't use modifiers like SHIFT, ALT, ...
    ->I can't check the modifiers during a keyPressEvent call
    ->It stops the other key :
    i see keyReleaseEvent calls even if i stay pressed, what the ??!
    -When you constantly press a key, the reaction is like in a text application : small delay before the event is fire continously

    In the two solutions, the application is fluid when the user keeps the key down, so that's cool. But in both cases, I've got glitches...
    What is the best thing to do ? How can I fix my problems ?

    Do I need to post some code ?

    Thanks!
    Last edited by jacek; 3rd July 2008 at 23:19. Reason: changed [qtclass] to [code]

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
  •  
Qt is a trademark of The Qt Company.