Inser into QTextEdit using QChar::ObjectReplacementCharacter crash after clear()
-
Hi all
I'm developing a software using Qt 4.8.4. I have a QTextEdit where I insert some custom objects as found in the "Text Object" example. The first time I insert my object all goes well. The problem happen after I call QTextEdit clear() method. Since I need to fill the editor with a new set of objects I clear all the content and start inser again. Unofrtunately it seem after called clear() insert new objects make crash the application. The debugger report me the crash into a realloc() function of a vector inside QTextEdit control. I'm currently using Visual Studio for developing. Currently I still was not able to find a workaround for this problem. Someone know a solution?
Thank you
-
Hi and welcome to devnet,
Could you post a minimum example of code that triggers the crash ?
-
Hi
Thank you for your reply
Well, a very short example could be the following:
@QTextCharFormat MyFormat;
QTextCursor Cursor;MyFormat.setObjectType(MyFormatType);
MyFormat.setProperty(PROPERTY1, Data1);
MyFormat.setProperty(PROPERTY2, Data2);
MyFormat.setProperty(PROPERTY3, Data3);Cursor = textCursor();
Cursor.insertText(QString(QChar::ObjectReplacementCharacter), MyFormat);
Cursor.insertText(" ");
setTextCursor(Cursor);@This code insert my custom objects into QTextEdit. This work very well the first insertion where I can insert a large number of objects. However when I need to clear all for make new insertions I call:
@MyEditText->clear();@
After this call that correctly clear all the editor content if I retry to execute the same insertion code above the crash described is reported. If could help I can report additional info based to my tests:
- if I countinue to add object without never call clear() no error is reported
- after called clear() I need to insert a number of object around more than 10/15 for generate the crash. If I add a few number no crash is reported (but I still didn't try to make the add operation of few elements more times)
- Instead to call clear() function I tried to select all elements by code and remove them but the result is the same crash
It seem clear() function doesn't correctly delete all the vector elements associated to the editor or some problem happen during vector realloc operation...
Thank you for the help
-
Thanks for the clarification.
I meant: could you post enough code that could be built to reproduce the crash. I can't really try to do anything from there.
-
No stress about it, you might even found yourself the solution while creating the demo.