[Interest] [QQuickView] deadlock on exit

Thiago Macieira thiago.macieira at intel.com
Wed Jan 8 19:13:38 CET 2014


On quarta-feira, 8 de janeiro de 2014 18:29:06, Tim Blechmann wrote:
> >> i will see what i can do ... what do i need to do in order to run exec()
> >> from a thread other than the main thread? afaict it wants to be called
> >> from the main thread, so simply creating a std::thread to run
> >> qApp->exec() does not work.
> > 
> > Start your thread using non-Qt means and make sure the *first* QObject
> > created is in that thread. QApplication is a QObject, so you may use
> > that.
> just to make sure that i'm understanding this correctly: the thread that
> creates the first QObject becomes qt's main thread?

Yes.

> this also implies that *all* other qt objects are created from this
> thread, instead of the main thread right?

All Qt widgets must be created in this thread. For our intents here in this 
mailing list, this *is* the GUI thread. It's not relevant that it is not the 
thread that ran the main() function.

> > If the plugin is not using Qt, there's no threading issue. Qt requires its
> > GUI to be run from one thread only, but it does not make any requirements
> > on GUIs written without Qt.
> 
> forgive my ignorance, maybe i'm missing something very stupid here: in
> the case of a plugin, the host provides a native handle (HWND or
> NSView*). i'm wrapping this native handle inside a QMacNativeWidget or
> qwinwidget and place a QQuickView inside.
> i'm not an expert with gui systems nor with qt, but from my
> understanding this implies that the plugin's gui has to run in the same
> thread as the host's gui. and therefore the QApplication must be created
> in the gui thread and not in a separate thread.
> and creating the QApplication in the gui thread, i cannot run exec()
> without blocking the host's gui.

Qt makes no such requirement. All it requires is that its GUI be run from one 
thread only, which we call the GUI thread. That thread must be the thread in 
which the first QObject is created. Since usually the first QObject created is 
QApplication or QCoreApplication in the main function, it's usually the main 
thread.

However, the underlying system API may make other requirements. I have no clue 
about the thread-safety of Win32 or Cocoa.

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20140108/92819d28/attachment.sig>


More information about the Interest mailing list