PDA

View Full Version : QEventLoop: Cannot be used without QApplication. Error in a multi-threaded library



hind
30th July 2013, 09:08
I'm making a library which contains a QThread object. I am going with the moveToThread style.
The DLL is successfully loaded but Qt Creator's application output gives QEventLoop: Cannot be used without QApplication.
I've done some searching work and it suggests I need a QApplication. I don't have a main() in the library so I have no idea where I can put the QApplication object.
Thanks in advance.

yeye_olive
30th July 2013, 09:40
The library itself should not instantiate QApplication, but every program loading it should.

hind
30th July 2013, 09:48
The library itself should not instantiate QApplication, but every program loading it should.
Yes I think so. But it just gives this error. My loader is a normal Qt GUI which already has QApplication.
Oh what if the load is not a Qt program which does not have any QApplication?

yeye_olive
30th July 2013, 10:27
But it just gives this error. My loader is a normal Qt GUI which already has QApplication.

You probably get this error because some QEventLoop is allocated by the library before the QApplication instance by the program. Does your library have a global variable (or static member field) of a QObject-derived type?


Oh what if the load is not a Qt program which does not have any QApplication?
Then you should not use QThread (and more generally QObjects) in your library as it depends on Qt's event loop for signal delivery.

hind
30th July 2013, 10:33
You probably get this error because some QEventLoop is allocated by the library before the QApplication instance by the program. Does your library have a global variable (or static member field) of a QObject-derived type?


Then you should not use QThread (and more generally QObjects) in your library as it depends on Qt's event loop for signal delivery.

Thank you for your replies. But when I accidentally swithed the loader from debug to release, the problem is gone...
And thanks for the second answer.