Qt调试:我如何知道QCoreApplication::notifyInternal2正在向哪个对象发送消息?

Qt debugging: How can I know which object QCoreApplication::notifyInternal2 is sending a message to?

本文关键字:对象 消息 调试 何知道 QCoreApplication Qt notifyInternal2      更新时间:2023-10-16

我有一个在另一个线程中运行QtCoreApplication的Windows服务。当服务停止时,程序总是崩溃。Qt似乎正在向已被清理的对象发送事件。

虽然我很确定我使用 deleteLater 清理所有对象。幸运的是,gdb 给了我输出,说程序在 notifyInternal2 上崩溃,这提示我崩溃是如何发生的。

但实际上,我很想知道崩溃发生在哪里。Qt中是否有调试日志级别,或者是否有一种方法可以判断事件尝试发送到哪个事件或哪个对象?

GDB 输出

Thread 4 received signal SIGSEGV, Segmentation fault.
[Switching to Thread 3492.0x980]
QCoreApplication::notifyInternal2 (receiver=0x2724bdd0,
event=event@entry=0x1a33e48) at kernel/qcoreapplication.cpp:1047
1047    kernel/qcoreapplication.cpp: No such file or directory.
(gdb) bt
#0  QCoreApplication::notifyInternal2 (receiver=0x2724bdd0,
event=event@entry=0x1a33e48) at kernel/qcoreapplication.cpp:1047
#1  0x01f91ef2 in QCoreApplication::sendEvent (event=0x1a33e48,
receiver=<optimized out>)
at ../../include/QtCore/../../src/corelib/kernel/qcoreapplication.h:234
#2  QCoreApplicationPrivate::sendPostedEvents (receiver=<optimized out>,
receiver@entry=0x0, event_type=<optimized out>, event_type@entry=52,
data=<optimized out>) at kernel/qcoreapplication.cpp:1740
#3  0x01f92579 in QCoreApplication::sendPostedEvents (
receiver=receiver@entry=0x0, event_type=event_type@entry=52)
at kernel/qcoreapplication.cpp:1594
#4  0x01f925ad in QCoreApplicationPrivate::execCleanup (this=0x19a4b38)
at kernel/qcoreapplication.cpp:1360
#5  0x01f93dec in QCoreApplication::exec ()
at kernel/qcoreapplication.cpp:1342
#6  0x004277bc in qtservice::windows::Handler::startup (this=0x19a8ce8,
argc=1, argv=0x1d3a9e8, service_status_handle=0x1d32c88)
at C:UsersmichaelDocumentsdevcppconnectlibQtServiceWindowsHandler.cpp:156
#7  0x004253f3 in qtservice::windows::Service::startup (this=0x28fe3c,
argc=1, argv=0x1d3a9e8)
at C:UsersmichaelDocumentsdevcppconnectlibQtServiceWindowsService.cpp:141
#8  0x004252b6 in qtservice::windows::Service::serviceMain(unsigned long, wchar_t**)@8 (argc=1, argv=0x1d3a9e8)
at C:UsersmichaelDocumentsdevcppconnectlibQtServiceWindowsService.cpp:100
#9  0x75a375a8 in SECHOST!I_ScIsSecurityProcess ()
from C:WindowsSysWOW64sechost.dll
#10 0x00000001 in ?? ()
#11 0x01d3a9e8 in ?? ()
#12 0x7715343d in KERNEL32!BaseThreadInitThunk ()
from C:Windowssyswow64kernel32.dll
#13 0x77879832 in ntdll!RtlInitializeExceptionChain ()
from C:WindowsSysWOW64ntdll.dll
#14 0x77879805 in ntdll!RtlInitializeExceptionChain ()
from C:WindowsSysWOW64ntdll.dll
#15 0x00000000 in ?? ()

Qt从不向被破坏的对象发送事件。如果是这样,那么这是另一个问题的症状:其他东西已经损坏了应用程序的状态。也许对象位于过早释放的内存区域中,因此对象本身从未被破坏,但它所在的内存是。