简体   繁体   中英

Ungraceful / kill Qt application when event loop is not started

How can I terminate a running Qt application ( QCoreApplication ) when exit does not work because the event loop is not yet started.

http://doc.qt.io/qt-5/qcoreapplication.html#exit

After this function has been called, the application leaves the main event loop and returns from the call to exec(). The exec() function returns returnCode. If the event loop is not running, this function does nothing

One (stupid?) approach I have found is to start the event loop and call QCoreApplication::exit again , but is this my best option?

If I am understanding your question correctly, you have not yet called QApplication::exec(), therefore your event loop has not started.

If you have not yet called exec() to start the event loop why not just call the stdlib exit() function or check the error condition before calling exec()

Eg in main.cpp

if(!somethingWentReallyWrong) {
    a.exec(); // Where a is your QApplication or QCoreApplication instance
} else {
    return myErrorCode;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM