Mikey A. Leonetti
Mikey A. Leonetti

Reputation: 3352

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

I have a Windows service that is running QtCoreApplication in another thread. The program always crashes when the service is stopped. It seems that Qt is sending an event to an object that's already been cleaned up.

Although I'm pretty sure I clean up all objects using deleteLater. Luckily, gdb gives me the output saying that the program is crashing on notifyInternal2 which tips me off to how the crash is happening.

But really, I'd love to know where the crash is happening. Is there a debugging log level in Qt or a way to tell what event or to which object the event is attempting to be sent to?

gdb output

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:\Users\michael\Documents\dev\cpp\connect\lib\QtService\Windows\Handler.cpp:156
#7  0x004253f3 in qtservice::windows::Service::startup (this=0x28fe3c,
    argc=1, argv=0x1d3a9e8)
    at C:\Users\michael\Documents\dev\cpp\connect\lib\QtService\Windows\Service.cpp:141
#8  0x004252b6 in qtservice::windows::Service::serviceMain(unsigned long, wchar_t**)@8 (argc=1, argv=0x1d3a9e8)
    at C:\Users\michael\Documents\dev\cpp\connect\lib\QtService\Windows\Service.cpp:100
#9  0x75a375a8 in SECHOST!I_ScIsSecurityProcess ()
   from C:\Windows\SysWOW64\sechost.dll
#10 0x00000001 in ?? ()
#11 0x01d3a9e8 in ?? ()
#12 0x7715343d in KERNEL32!BaseThreadInitThunk ()
   from C:\Windows\syswow64\kernel32.dll
#13 0x77879832 in ntdll!RtlInitializeExceptionChain ()
   from C:\Windows\SysWOW64\ntdll.dll
#14 0x77879805 in ntdll!RtlInitializeExceptionChain ()
   from C:\Windows\SysWOW64\ntdll.dll
#15 0x00000000 in ?? ()

Upvotes: 1

Views: 733

Answers (1)

Qt never sends events to destroyed objects. If it does, then it's a symptom of another problem: something else has corrupted the state of the application already. Perhaps the object is in a memory area that got prematurely freed, so that the object itself was never destructed, but the memory where it resided - was.

Upvotes: 1

Related Questions