为什么从析构函数调用时 qCritical 或 qDebug 不起作用?
我有一个多线程应用程序,最初是使用 Qt 4.6 和 Qt Creator 2.2(或可能是 2.1)开发的,最近我升级到 Qt 4.7 和 Qt Creator 2.3(这都是在 Windows 中)。我之前曾通过调用
然而,升级到较新版本后,我注意到这些消息并不总是显示在 Qt Creator 中的“应用程序输出”面板中。消息的顺序始终是正确的,但在某个随机点,输出会停止显示。有时根本不显示任何输出。尽管如此,我可以确认对象正在被销毁,并且我的应用程序退出时没有错误。
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因为 qDebug 与 QApplication 交互,并且现在可能它的某些部分在应用程序的所有其他部分之前被销毁。或许。
但是,请尝试手动销毁对象,然后再调用 QApplication::exit();
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();