简体   繁体   中英

Why wouldn't qCritical or qDebug work when called from a destructor?

I have a multi-threaded application I was originally developing using Qt 4.6 and Qt Creator 2.2 (or possibly 2.1), and recently I upgraded to Qt 4.7 and Qt Creator 2.3 (this is all in Windows). I had previously been testing the destruction order of the various threads and objects in my application by placing calls to qCritical() in the destructors. It easily confirmed that things were being destroyed in the order I expected.

However, after upgrading to the newer versions I noticed that the messages are not always displayed to the Application Output panel in Qt Creator. The order of the messages is always correct, but at some random point the output just stops being shown. Sometimes no output is shown at all. Nevertheless, I can confirm that the objects are being destroyed and my application exits without error.

The problem still occurs when I use qDebug() to display messages, but everything displays fine if I instead use a simple printf() . What could be the reason for the Application Output stopping before the application completes its clean-up? Are there changes to the newest versions of Qt or Qt Creator that alter how these functions may behave when called from inside a destructor?

Because qDebug interacts with QApplication, and, may be, now some part of it gets destroyed before all other parts of application. May be. However, try destroying your objects manually, and only then call for QApplication::exit();

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