0

I've got a problem with my Qt 4.8 slot which is connected that way:

connect(ui->objectTree->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)), this, SLOT(syncGuiWithTreeSelection(const QItemSelection&, const QItemSelection&)));

the slot has this signature:

void MyClass::syncGuiWithTreeSelection(const QItemSelection &itemSelected, const QItemSelection &itemDeselected)

In the above slot I wanted to access the selected indexes like that:

const QModelIndexList &indexes = itemSelected.indexes();

Which works nicely BUT at the end of the slot, when the desctructor of QModelIndexList is called, a DEBUG_ASSERTION_FAILURE shows up. The call stack looks like that:

msvcr90d.dll!operator delete(void * pUserData=0x03673968)  Line 52 + 0x51 bytes C++
MyClass.exe!QModelIndex::`scalar deleting destructor'()  + 0x32 bytes   C++
MyClass.exe!QList<QModelIndex>::node_destruct(QList<QModelIndex>::Node * from=0x0371c4c4, QList<QModelIndex>::Node * to=0x0371c4c8)  Line 431 + 0x2f bytes  C++
MyClass.exe!QList<QModelIndex>::free(QListData::Data * data=0x0371c4b0)  Line 759   C++
MyClass.exe!QList<QModelIndex>::~QList<QModelIndex>()  Line 733 C++
MyClass.exe!MyClass::syncGuiWithTreeSelection(const QItemSelection & itemSelected={...}, const QItemSelection & itemDeselected={...})  Line 853 + 0xc bytes C++
MyClass.exe!MyClass::qt_static_metacall(QObject * _o=0x001ef69c, QMetaObject::Call _c=InvokeMetaMethod, int _id=49, void * * _a=0x001eca04)  Line 247 + 0x20 by

What can I do to be able to access the selected indexes?

kind regards, reinhart

rherzog
  • 51
  • 9
  • What else do you do in your slot? It looks like you delete some objects twice. – vahancho Mar 04 '14 at 08:38
  • it just contains "itemSelected.indexes();". When that statement is removed everything happens to be fine. The same error occures if I try to access the selectedIndexes via "ui->objectTree->selectionModel()->selectedIndexes()" in the slot. If I put that statement after the connect, everything is fine. Am I doing something wrong with the slot? It seems as if there is a general problem accessing the selectedIndexes in the slot. – rherzog Mar 04 '14 at 09:10
  • `QItemSelection::indexes()` returns the `QModelIndexList`, so I think you need to call: `QModelIndexList indexes = itemsSelected.indexes()` instead. – vahancho Mar 04 '14 at 09:32
  • just tried it - doesn't work. The statement `QItemSelection::indexes()` is enough for the code to break. – rherzog Mar 04 '14 at 10:21

0 Answers0