marcvanriet
19th August 2011, 02:23
Hi,
I have a strange crash in a small app of mine, and I could trace it back to something I believe is related to implicit sharing of a QString.
This is sort of what happens :
- i receive a text message over TCP/IP
- this message is parsed using QJSON
- a value of a certain field is taken from the QJSON output as a QString
- this value is shown in a QLineEdit using setText()
Now, when the same value is written twice to the QLineEdit, a crash occurs.
This is my stack trace :
0 DbgBreakPoint ntdll 0x7c90120e
1 RtlpNtMakeTemporaryKey ntdll 0x7c96f26e
2 RtlValidateHeap ntdll 0x7c962fe0
3 HeapValidate kernel32 0x7c85f9a7
4 CrtIsValidHeapPointer MSVCR80D 0x102115ba
5 free_dbg MSVCR80D 0x102107a6
6 free_dbg MSVCR80D 0x1021065e
7 free MSVCR80D 0x102105de
8 qFree qmalloc.cpp 60 0x4ab8bd
9 QString::free qstring.cpp 1108 0x5135bf
10 QString::~QString qstring.h 869 0x47bff3
11 QLineControl::internalSetText qlinecontrol.cpp 637 0x655d3349
12 QLineControl::setText qlinecontrol_p.h 577 0x65560b07
13 QLineEdit::setText qlineedit.cpp 384 0x655caa06
So the crash is really inside Qt's internal functions. The crash does NOT occur if I first copy the value to another string and modify it (e.g. when I do toUpper()). But when I just copy the string, or when the original is already uppercase, then the crash occurs. This shows to me that the problem only occurs when the value written to the QLineEdit is an implicit copy of something else.
The quick-and-dirty solution so that I can move on with the program is to make a copy of the string that is not implicitely shared. But is there a way to do that ?
Regards,
Marc
I have a strange crash in a small app of mine, and I could trace it back to something I believe is related to implicit sharing of a QString.
This is sort of what happens :
- i receive a text message over TCP/IP
- this message is parsed using QJSON
- a value of a certain field is taken from the QJSON output as a QString
- this value is shown in a QLineEdit using setText()
Now, when the same value is written twice to the QLineEdit, a crash occurs.
This is my stack trace :
0 DbgBreakPoint ntdll 0x7c90120e
1 RtlpNtMakeTemporaryKey ntdll 0x7c96f26e
2 RtlValidateHeap ntdll 0x7c962fe0
3 HeapValidate kernel32 0x7c85f9a7
4 CrtIsValidHeapPointer MSVCR80D 0x102115ba
5 free_dbg MSVCR80D 0x102107a6
6 free_dbg MSVCR80D 0x1021065e
7 free MSVCR80D 0x102105de
8 qFree qmalloc.cpp 60 0x4ab8bd
9 QString::free qstring.cpp 1108 0x5135bf
10 QString::~QString qstring.h 869 0x47bff3
11 QLineControl::internalSetText qlinecontrol.cpp 637 0x655d3349
12 QLineControl::setText qlinecontrol_p.h 577 0x65560b07
13 QLineEdit::setText qlineedit.cpp 384 0x655caa06
So the crash is really inside Qt's internal functions. The crash does NOT occur if I first copy the value to another string and modify it (e.g. when I do toUpper()). But when I just copy the string, or when the original is already uppercase, then the crash occurs. This shows to me that the problem only occurs when the value written to the QLineEdit is an implicit copy of something else.
The quick-and-dirty solution so that I can move on with the program is to make a copy of the string that is not implicitely shared. But is there a way to do that ?
Regards,
Marc