Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Crash of QListWidget when renaming item by program
I have a QListWidget to which I add items with the following:
Then when I run the code, I can click on the different items and my code takes the proper actions. No problem with that!
The problem arises when, for some reasons that are too long (and useless) to explain I call a function that renames the selected item. This function contains the line:
When this function is called, the item gets properly renamed. But if I select another item and reselect the item that I just renamed, then the code crashes with the error message:
[quote]ASSERT failure in QVector<T>::operator: "index out of range", file /usr/include/qt5/QtCore/qvector.h, line 369[/quote]
Anything I am doing wrong?
msue last edited by
Not with the two lines you posted. The problem has to do with the rest of your code.
But if I comment the line
then the code doesn't crash when I select another item and reselect the item that I want to change the name.
andreyc last edited by
As msue said it is hard to tell what happens with only two lines of code.
I guess that selected and current items are not the same.
You can have a "list":http://qt-project.org/doc/qt-5/qlistwidget.html#selectedItems of selected items but a current item is only one.
Try to check what is the result of MyList->currentItem() before trying to set a text.
Thank you, I'll check that!