PDA

View Full Version : Qt 4.7 + QGLWidget causes lock up when window resizes/moves



jmeb2206
18th April 2011, 05:44
I recently just got Qt 4.7 (from Qt 4.6.1). Ever since then any application that I create a QGLWidget for are causing that application to lock up whenever I move/resize the main window. When I resize, the mouse stays on the resize cursor. When I try to move the window nothing happens. In both cases my machine locks up and I have to ctrl+alt+delete to get out of this state. I tested the sample example below with Qt 4.6.1 that I had before and this works without any problems so it's something new with Qt 4.7. Any help would be greatly appreciated. Thanks!




MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);

myTimer = new QTimer(this);

myGlWidget = new QGLWidget(this);

connect(myTimer, SIGNAL(timeout()), this, SLOT(updateRender()));

myTimer->start(0);
}

void MainWindow::updateRender()
{
if(myGlWidget)
{
myGlWidget->updateGL();
}
}

high_flyer
18th April 2011, 10:09
This:


myGlWidget = new QGLWidget(this);

connect(myTimer, SIGNAL(timeout()), this, SLOT(updateRender()));

myTimer->start(0);


will cause your GL widget to update continuously( after other events have been processed).
Why do you use such a construct in the first place?
Are you sure this is what you want?
This could also explain the behavior you are experiencing, depending on how you implemented updateGL().


I tested the sample example below with Qt 4.6.1 that I had before and this works without any problems so it's something new with Qt 4.7.
If you did something wrong before which 4.6 somehow allowed, the fact 4.7 is not allowing it doesn't necessarily mean the problem is with the new Qt version (more like with the older version).

jmeb2206
19th April 2011, 04:23
Thank you for your reply. Yes I do realize that this will cause the GL widget to update continuously, which is what I want as I am creating an animation. Is there a better way to do this?

Also, in the example I give I am doing nothing but creating a Qt QGLWidget, not a derived one. So I am not re-implementing updateGL() or anything, I'm just using pure Qt code. I found that if I changed the timer to delay for about 20 msecs then the application no longer locks up, so I'm guessing that Qt doesn't really want you use a timer in this fashion anymore as it doesn't properly get a chance to handle the other events. It wasn't just 4.6 that this worked for I've done this with 4.2 up until now.

high_flyer
19th April 2011, 10:22
Yes I do realize that this will cause the GL widget to update continuously, which is what I want as I am creating an animation.
But you are updating your widget even when no animation is going on...
You should start the timer when you want to animate something, and stop it when the animation is finished.
Also, a 0 timer is a bit extreme for animation, the human eye will perceive a smooth motion with 24 fps, which is about 40ms.
With a 0 timer you are making your application use CPU cycles that it doesn't need.

If you make a simple project which only has a QGLWidget and a 0 timer, and it still locks, you might want to register a bug, with the code for reproducing it.
However, at least based on the code you posted, I can't explain why you experience a lockup.

jmeb2206
20th April 2011, 03:46
The animation, the sun in my case, should never stop until the program closes. With the previous versions, 4.2-4.6, I was getting 60fps but now I have to use the 20ms delay and I get 45fps. Yes I realize that this is still acceptable to perceive a smooth animation but it's kind of a bummer that I'm not able to render as fast as I use to. I can only imagine that if I had a more complex scene to render that I would lose even more fps. The sample code I posted does just have a QGLWidget and a 0 timer, so I'll go with that to register a bug. Thanks for helping.