Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Crash in QString destructor (while fetching reference count).
Bart_Vandewoestyne last edited by Bart_Vandewoestyne
I have a class
Barwith 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:
QStringdestructor 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 (
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
QStringand 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.
I would guess you're deleting your class 'Bar' twice but it's only a guess without a reproducible minimal example.