为什么从析构函数调用时 qCritical 或 qDebug 不起作用?

发布于 2024-12-16 01:30:59 字数 515 浏览 1 评论 0原文

我有一个多线程应用程序,最初是使用 Qt 4.6 和 Qt Creator 2.2(或可能是 2.1)开发的,最近我升级到 Qt 4.7 和 Qt Creator 2.3(这都是在 Windows 中)。我之前曾通过调用

然而,升级到较新版本后,我注意到这些消息并不总是显示在 Qt Creator 中的“应用程序输出”面板中。消息的顺序始终是正确的,但在某个随机点,输出会停止显示。有时根本不显示任何输出。尽管如此,我可以确认对象正在被销毁,并且我的应用程序退出时没有错误。

当我使用 qDebug() 显示消息,但如果我使用简单的 printf() ,则一切都显示正常。应用程序输出在应用程序完成清理之前停止的原因可能是什么? Qt 或 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦境 2024-12-23 01:30:59

因为 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();

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文