Results 1 to 3 of 3

Thread: Static QEventLoop gives message "QEventLoop: Cannot be used without QApplication"

  1. #1
    Join Date
    Jun 2012
    Posts
    202
    Thanks
    22
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Static QEventLoop gives message "QEventLoop: Cannot be used without QApplication"

    I have need for a local event loop to block code execution while continuing to process QEvents.

    I use QEventLoop and it's working as expected--call it tcExecuting.

    The code that calls tclExecuting.exec() blocks until tclExecuting's exit() slot is called via a connected signal.

    The QEventLoop is static and declared outside of any function/method like this:

    QEventLoop TclInterp::tclExecuting;

    At runtime, before the first line of main() I get the message:


    QEventLoop: Cannot be used without QApplication
    Not sure what this message is trying to tell me. Can I safely ignore it?

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,153
    Thanks
    295
    Thanked 854 Times in 841 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Static QEventLoop gives message "QEventLoop: Cannot be used without QApplication"

    Static variables are constructed on the stack on program startup, before the main() function is entered. So since your static event loop instance is constructed before main() executes and probably before your QApplication instance (because that usually occurs in main()), that's why you get the warning.

    I don't know if this is harmful or not. What I would suggest is that you turn this into a pointer to a static QEventLoop, and initialize the pointer (through new()) after your QApplication instance has been constructed, then use it by dereferencing the pointer.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

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

    davethomaspilot (30th August 2022)

  4. #3
    Join Date
    Jun 2012
    Posts
    202
    Thanks
    22
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Static QEventLoop gives message "QEventLoop: Cannot be used without QApplication"

    Quote Originally Posted by d_stranz View Post
    Static variables are constructed on the stack on program startup, before the main() function is entered. So since your static event loop instance is constructed before main() executes and probably before your QApplication instance (because that usually occurs in main()), that's why you get the warning.

    I don't know if this is harmful or not. What I would suggest is that you turn this into a pointer to a static QEventLoop, and initialize the pointer (through new()) after your QApplication instance has been constructed, then use it by dereferencing the pointer.
    Giving it a try. Thanks!


    Added after 5 minutes:


    Yes, that hushed the message.

    Thanks!
    Last edited by davethomaspilot; 30th August 2022 at 19:13.

Similar Threads

  1. Replies: 13
    Last Post: 20th February 2015, 00:07
  2. Replies: 4
    Last Post: 30th July 2013, 11:33
  3. QEventLoop in QApplication
    By Qiieha in forum Qt Programming
    Replies: 1
    Last Post: 22nd May 2012, 20:08
  4. static QEventLoop strange behavior
    By SABROG in forum Qt Programming
    Replies: 2
    Last Post: 29th July 2009, 13:04
  5. Replies: 4
    Last Post: 12th October 2008, 14:47

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.