Results 1 to 3 of 3

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

  1. #1
    Join Date
    Jun 2012
    Posts
    219
    Thanks
    28
    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,236
    Thanks
    303
    Thanked 864 Times in 851 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
    219
    Thanks
    28
    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 18:13.

Similar Threads

  1. Replies: 13
    Last Post: 19th February 2015, 23:07
  2. Replies: 4
    Last Post: 30th July 2013, 10:33
  3. QEventLoop in QApplication
    By Qiieha in forum Qt Programming
    Replies: 1
    Last Post: 22nd May 2012, 19:08
  4. static QEventLoop strange behavior
    By SABROG in forum Qt Programming
    Replies: 2
    Last Post: 29th July 2009, 12:04
  5. Replies: 4
    Last Post: 12th October 2008, 13: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.