[Qt-interest] Non-blocking windows drag-n-drop

Ross Bencina rossb-lists at audiomulch.com
Tue Sep 1 05:55:00 CEST 2009


on Tuesday, September 01, 2009 2:41 AM Aron Bierbaum wrote:
>I finally got back to looking into my problem and it appears that it
> is because my application is manually processing events. Since my
> application is updating a scene graph that is being rendered in a
> QGraphicsScene once I start dragging, my application loop freezes, but
> Qt does continue to pump events. For example my application would do
> the following:
>
>
> while running:
>  updateSceneGraph()
>  app.processEvents()
>
> The issue that I am seeing is that once a drag starts I don't get any
> calls into updateSceneGraph(). I guess that is what I get for manually
> pumping the Qt event loop. My only other idea would be to create a
> QTimer() temporarily to call back into my application. :(


I'm not sure why you're doing it that way (perhaps for good reason) but it
isn't the recommended way of running an event loop.

I do all of my scene graph animation using timers. The way you've
implemented it, you're updating the scene graph as fast as possible.
According to the docs QTimer should give you that behavior with a 0 interval
(the default). So I'd rewrite your code something like:

QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(updateSceneGraph()));
timer->start();
app.exec();

If you don't like the idea of a signal dispatch for every update you could
use the QObject timerEvent function instead.

Ross.

===================================
AudioMulch 2.0 is here!

http://www.audiomulch.com




More information about the Qt-interest-old mailing list