PDA

View Full Version : GUI Unhappy With QTimer



qtoptus
18th October 2011, 16:13
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?




QTimer timer;

timer.setInterval(0);

connect(&timer, SIGNAL(timeout()), SLOT(onIdle()));

timer.start();


...::onIdle()
{

// do something...

}



Thanks.

Jonny174
19th October 2011, 03:33
Try this:


...::onIdle()
{
// do something...
qApp->processEvents();
}

ChrisW67
19th October 2011, 04:31
The UI is blocked until "do something" finishes. If "do something" is long running then you should read: Keeping the GUI responsive

qtoptus
19th October 2011, 05:18
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.

qtoptus
19th October 2011, 16:12
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.

qtoptus
19th October 2011, 22:59
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.