Results 1 to 6 of 6

Thread: GUI Unhappy With QTimer

  1. #1
    qtoptus Guest

    Default GUI Unhappy With QTimer

    Hello,

    I'm trying to implement an on-idle event for a single window application. What I did is creating a timer in the main window class and set the time out interval to 0. The on-idle callback function is invoked with no problem except that when the timer's timeout is 0, the application window's titlebar context menu does not render it's text until i hover over the items. So when rightclicking the title bar the menu shows but no items are rendered. Any idea why the timer causing this? Is there any work around?

    Qt Code:
    1. QTimer timer;
    2.  
    3. timer.setInterval(0);
    4.  
    5. connect(&timer, SIGNAL(timeout()), SLOT(onIdle()));
    6.  
    7. timer.start();
    8.  
    9.  
    10. ...::onIdle()
    11. {
    12.  
    13. // do something...
    14.  
    15. }
    To copy to clipboard, switch view to plain text mode 

    Thanks.
    Last edited by qtoptus; 18th October 2011 at 17:29.

  2. #2
    Join Date
    Apr 2011
    Location
    Russia
    Posts
    85
    Thanks
    2
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: GUI Unhappy With QTimer

    Try this:
    Qt Code:
    1. ...::onIdle()
    2. {
    3. // do something...
    4. qApp->processEvents();
    5. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: GUI Unhappy With QTimer

    The UI is blocked until "do something" finishes. If "do something" is long running then you should read: [wiki=Keeping_the_GUI_Responsive]Keeping the GUI responsive[/wiki]

  4. #4
    qtoptus Guest

    Default Re: GUI Unhappy With QTimer

    I did. It solved the problem, but it created another which is now the context menu stucks cannot be closed or perform any action on the main window
    like closing or resizing...

    I'm using another timer btw, the boost::chrono inside the QTimer event to lock to a specific frame rate.

  5. #5
    qtoptus Guest

    Default Re: GUI Unhappy With QTimer

    Not lengthy operation at all. It's supposed to do "something" that does not take longer than 1/60 of a second.

    the app->processEvents() did not really solve the problem. It prevents window events abruptly.

    The version I'm using is 7.4.7. Probably a bug? Something not suitable for Qt?

    So if this is the case, I would suggest for the 4.8 or future releases to expose a standard OnIdle event handler instead of hacking it using a timer.

  6. #6
    qtoptus Guest

    Default Re: GUI Unhappy With QTimer

    Yup it's a big bug. I already reported this bug to the Qt team. Hopefully it'll be solved in the next release. Thanks for help anyway.

Similar Threads

  1. Use a QTimer in a Qt-non-GUI app.
    By hakermania in forum Newbie
    Replies: 11
    Last Post: 29th August 2010, 10:36
  2. Use of QTimer
    By A.H.M. Mahfuzur Rahman in forum Qt Programming
    Replies: 4
    Last Post: 7th August 2009, 13:52
  3. QTimer
    By link7 in forum Newbie
    Replies: 4
    Last Post: 2nd June 2009, 08:35
  4. QTimer
    By Ahmad in forum Qt Programming
    Replies: 1
    Last Post: 22nd October 2007, 18:26
  5. QTimer
    By nirup in forum Qt Programming
    Replies: 1
    Last Post: 29th May 2007, 14:13

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.