Important: Please read the Qt Code of Conduct -

Crash in QString destructor (while fetching reference count).

  • I have a class Bar with a member variable of type QString. When the destructor of this class is called, I get a crash with the error message:

    Exception thrown: read access violation.
    _q_value was 0x58A0620.
    If there is a handler for this exception, the program may be safely continued.

    The top of the call stack looks as follows:

    Qt5Cored.dll!QGenericAtomicOps<QAtomicOpsBySize<4> >::load<int>(const int & _q_value) Line 90   C++
    Qt5Cored.dll!QBasicAtomicInteger<int>::load() Line 103  C++
    Qt5Cored.dll!QtPrivate::RefCount::deref() Line 66       C++
    Qt5Cored.dll!QString::~QString() Line 1135      C++
    Foo.dll!Bar::~Bar()     C++
    ... irrelevant stuff ...

    So I think what happens is the following:

    • QString destructor is called, so the reference count to the shared data must be decreased by one.
    • To decrease the reference count, the current reference count value is loaded (atomically).
    • Loading the current reference count (_q_value) fails.

    I have no idea why this happens and am looking for suggestions for what I could possibly doing wrong in my code (certain anti-patterns related to QString and implicit data sharing???)

    Any hint on what to look for in order to diagnose and fix this problem is very welcome. I cannot share any code due to company restrictions. Qt version we are using is our own build of Qt 5.12.2.

  • Lifetime Qt Champion

    I would guess you're deleting your class 'Bar' twice but it's only a guess without a reproducible minimal example.

Log in to reply