Results 1 to 5 of 5

Thread: QEventLoop: Cannot be used without QApplication. Error in a multi-threaded library

  1. #1
    Join Date
    Mar 2013
    Posts
    28
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Windows

    Default QEventLoop: Cannot be used without QApplication. Error in a multi-threaded library

    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.

  2. #2
    Join Date
    Oct 2009
    Posts
    483
    Thanked 97 Times in 94 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QEventLoop: Cannot be used without QApplication. Error in a multi-threaded librar

    The library itself should not instantiate QApplication, but every program loading it should.

  3. The following user says thank you to yeye_olive for this useful post:

    hind (30th July 2013)

  4. #3
    Join Date
    Mar 2013
    Posts
    28
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QEventLoop: Cannot be used without QApplication. Error in a multi-threaded librar

    Quote Originally Posted by yeye_olive View Post
    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?
    Last edited by hind; 30th July 2013 at 11:01.

  5. #4
    Join Date
    Oct 2009
    Posts
    483
    Thanked 97 Times in 94 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QEventLoop: Cannot be used without QApplication. Error in a multi-threaded librar

    Quote Originally Posted by hind View Post
    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?

    Quote Originally Posted by hind View Post
    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.

  6. The following user says thank you to yeye_olive for this useful post:

    hind (30th July 2013)

  7. #5
    Join Date
    Mar 2013
    Posts
    28
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QEventLoop: Cannot be used without QApplication. Error in a multi-threaded librar

    Quote Originally Posted by yeye_olive View Post
    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.

Similar Threads

  1. Multi-threaded rendering advice
    By jcox23 in forum Qt Programming
    Replies: 0
    Last Post: 5th November 2012, 12:25
  2. QEventLoop in QApplication
    By Qiieha in forum Qt Programming
    Replies: 1
    Last Post: 22nd May 2012, 20:08
  3. Debugging a multi threaded windows app
    By Cruz in forum Qt Programming
    Replies: 5
    Last Post: 10th April 2012, 13:46
  4. Multi-threaded GUI possible?
    By nurtsi in forum Qt Programming
    Replies: 12
    Last Post: 26th November 2010, 22:52
  5. Qstring toStdString() and Multi-threaded DLL (/MD)
    By Daxos in forum Qt Programming
    Replies: 14
    Last Post: 15th May 2010, 12:57

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.