Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Crash with QItemSelectionModel::selectedIndexes()
scoobyff666 last edited by
I have read about this problem all over the internet, but always with different solutions and none worked for me.
When I run the following code:
@QModelIndexList il = placeList->selectionModel()->selectedIndexes(); //placeList is a QListView@
a crash occurs. But the crash does not happen when executing this line of code. It happens when the program is destructing the QList object, in @Q_INLINE_TEMPLATE void QList<T>::node_destruct(Node *from, Node *to) @ .
This does not happen because the list is invalid or something like that. When I check it, the size of the list is exactly the size of the selection and the indexes are the right ones. This message appears when the program crashes:
bq. Debug Assertion Failed!
Expression: _pFirstBlock == pHead
When running the Release build, the program crashes too, but without this message, obviously.
Some people say this problem only happens when building Debug with Release libraries, other say this only happens in Release, and everybody I see having this problem is using Qt4.7 or < ... I'm using 5.0 and the crash occurs in Debug and Release builds, using debug libraries in Debug and release libraries in Release.
I'm adding here the simplest possible code that will cause this problem, so you can analyse and test it. Is just a main.cpp file:
void doSomethingWithSelection(QItemSelectionModel* selectionmodel);
int main(int argc, char *argv)
QApplication a(argc, argv);
QStringList list; list.push_back("1"); list.push_back("2"); list.push_back("3"); list.push_back("4"); QStringListModel model(list); QListView view; view.setModel(&model); view.setSelectionMode(QAbstractItemView::ExtendedSelection); QItemSelectionModel *selectionmodel = view.selectionModel(); QModelIndex first = model.index(0); QModelIndex last = model.index(2); QItemSelection selection(first, last); selectionmodel->select(selection,QItemSelectionModel::Select); doSomethingWithSelection(selectionmodel); view.show(); return a.exec();
void doSomethingWithSelection(QItemSelectionModel* selectionmodel)
QModelIndexList indexlist = selectionmodel->selectedIndexes();
// this is what causes the error. I put this inside a function
// so the error will happen when exiting the function,
// when the program try to destroy the list nodes.
scoobyff666 last edited by
Hi folks. I'm answering myself here with quite a non-conclusive answer, but I managed to solve the problem. Right now I don't understande why this works, yet:
In my Qt project, I was using a Kit with Microsoft Windows SDK for Windows 7 (7.0.7600.16385.40715) (x86) as compiler. When I changed the compiler to Microsoft Visual C++ Compiler 10.0 (x86) this code worked correctly.
I really don't know what this means.. as far as I know Windows SDK is an SDK, not a compiler. Can someone please explain to me this situation?
From the top of my head, compiler mismatch between your code and the Qt libraries