QDebug can’t be used from a destructor of a static object

We can’t do this in QT:

class Global
{
public:

    ~Global()
    {
        qDebug() << "Global destructor.";
    }
};

Global g;

This crashes on MacOS with the following stack trace:

1 __pthread_kill (x86_64) /usr/lib/system/libsystem_kernel.dylib 0x7fff2034c92e
2 pthread_kill (x86_64) /usr/lib/system/libsystem_pthread.dylib 0x7fff2037b5bd
3 abort (x86_64) /usr/lib/system/libsystem_c.dylib 0x7fff202d0406
4 malloc_vreport (x86_64) /usr/lib/system/libsystem_malloc.dylib 0x7fff201b0165
5 malloc_report (x86_64) /usr/lib/system/libsystem_malloc.dylib 0x7fff201b32aa
6 QTypedArrayData<char16_t>::deallocate(QArrayData *) qarraydata.h 124 0x1001d90fb
7 QArrayDataPointer<char16_t>::~QArrayDataPointer() qarraydatapointer.h 95 0x1001d90ec
8 QArrayDataPointer<char16_t>::~QArrayDataPointer() qarraydatapointer.h 92 0x1001d90d9
9 QString::~QString() qstring.h 1334 0x1001d90d9
10 QString::~QString() qstring.h 1334 0x1001d90d9
11 AppleUnifiedLogger::messageHandler(QtMsgType, QMessageLogContext const&, QString const&, QString const&) qcore_mac.mm 135 0x1001d90d9
12 qDefaultMessageHandler(QtMsgType, QMessageLogContext const&, QString const&) qlogging.cpp 1822 0x100088700
13 qt_message_print(QtMsgType, QMessageLogContext const&, QString const&) qlogging.cpp 1874 0x100088678
14 qt_message_output(QtMsgType, QMessageLogContext const&, QString const&) qlogging.cpp 1925 0x10008856d
15 QDebug::~QDebug() qdebug.cpp 167 0x10008c2e7
16 (anonymous namespace)::Global::~Global() main.cpp 39 0x1000551ba
17 (anonymous namespace)::Global::~Global() main.cpp 38 0x100055124
18 __cxa_finalize_ranges (x86_64) /usr/lib/system/libsystem_c.dylib 0x7fff202aad25
19 exit (x86_64) /usr/lib/system/libsystem_c.dylib 0x7fff202ab010
20 start (x86_64) /usr/lib/system/libdyld.dylib 0x7fff20396f44

Leave a Reply

Your email address will not be published.