[Qt-interest] Qt, DirectX and MultiThreading
Ross Bencina
rossb-lists at audiomulch.com
Thu Apr 15 12:43:49 CEST 2010
Ender EREL wrote:
> Everything was going perfectly, until i opened a modal dialog
> (QFileDialog to be exact), which stops the execution of Qt's Event Loop,
> which manages QTimers including the most important QTimer for me: the
> QTimer (a zero-timer) that triggers the DirectX rendering. I facepalm'd.
>
> So, when a modal dialog is opened (or QApplication event-loop is blocked
> in some way) my rendering stops, which is not critical, but creates an
> unpleasant experience.
Hmm yeah. There must be a way to get the timer events delivered in the main
thread while a dialog is visible (I hope, since I have a similar problem to
solve sooner or later)...
Perhaps you could just have another thread (or windows timer) post a custom
QEvent back to the main window to trigger the repaint -- hopefully custom
events don't get filtered while the dialog is visible.
> I did what any developer would do. I debugged. And found out that my
> main thread hangs at QRasterWindowSurface::flush(), line 185, where it
> calls BitBlt. Examining the stack trace, i saw that the widget that
> causes the hanging is not my DirectX Widget but its parent's parent,
> which is a top level window. I will paste the stack trace below, if
> anyone is still reading and wants to take a look.
Well, my first question is, does the Widget whose HWND you're using with
DirectX have the Qt::WA_NativeWindow attribute set? Try that. Also make sure
you request the HWND _after_ your widget has been shown (even if you have to
show it outside visible bounds). I had all sorts of problems getting Qt to
give me a stable HWND until I followed these steps. Calling WinId() is not
enough.
Failing that, I'm a bit hazy on this, but I thought you're only supposed to
talk to a HWND in the thread in which you created it (check MSDN for
details)... so you might need to create your DX hosting HWND in your second
thread and parent it to the HWND from the main thread. Could be wrong about
that though...
Good luck!
Ross.
More information about the Qt-interest-old
mailing list