Many places in the Qt docs we are warned that the QApplication must only be created on the "main thread", and similarly for all GUI objects. But there is no explanation. Does "main thread" really mean the one created by the OS to start a new process? And if so, why does QApplication require that? Couldn't it just as well live on any thread of a process?
I'm asking because (like many others) I would like to add a Qt-based GUI to an existing command line program, something like this: the app creates a new thread to run the gui initialization routine, which creates a QApplication and calls its exec(). Then the app 'main' thread creates a QObject that sets up queued signal connections to gui functions, and emits those signals in fns callable from the app. Any required blocking/unblocking of the main thread is handled outside Qt (e.g. in libpthread). It seems to me this satisfies the thread-safeness rules of Qt, except possibly "the QApplication must live on the main thread". Why shouldn't it work?
Thanks for your advice
-- Tom
Bookmarks