hi,
i get a selection model from a treeview and connect signal
selectionChanged to the following method:
void
Container_Widget::selectionChanged(const QItemSelection& selected,
const QItemSelection& deselected)
{
printf("<Container_Widget::selection changed()>\n");
fflush(stdout);
QModelIndexList indexlist = selected.indexes();
QListIterator<QModelIndex> it(indexlist);
while(it.hasNext()) {
if(!modelindex.isValid()) {
printf("Container_Widget::selectionChanged() : model index not valid \n");
fflush(stdout);
continue;
}
printf("Container_Widget::selectionChanged() : row = %d, col = %d \n",
modelindex.row(), modelindex.column() );
fflush(stdout);
Container_ModelItem* item
= static_cast<Container_ModelItem*>(modelindex.internalPointer());
... call some method of item -> segfault !!
}
printf("</Container_Widget::selection changed()>\n");
fflush(stdout);
}
void
Container_Widget::selectionChanged(const QItemSelection& selected,
const QItemSelection& deselected)
{
printf("<Container_Widget::selection changed()>\n");
fflush(stdout);
QModelIndexList indexlist = selected.indexes();
QListIterator<QModelIndex> it(indexlist);
while(it.hasNext()) {
QModelIndex modelindex = it.next();
if(!modelindex.isValid()) {
printf("Container_Widget::selectionChanged() : model index not valid \n");
fflush(stdout);
continue;
}
printf("Container_Widget::selectionChanged() : row = %d, col = %d \n",
modelindex.row(), modelindex.column() );
fflush(stdout);
Container_ModelItem* item
= static_cast<Container_ModelItem*>(modelindex.internalPointer());
... call some method of item -> segfault !!
}
printf("</Container_Widget::selection changed()>\n");
fflush(stdout);
}
To copy to clipboard, switch view to plain text mode
the problem is that the internal pointer of the model index
cannot be of class Container_ModelItem,
since if i call a method of this class the program crashes.
i checke already all methods of the model which return a QModelIndex,
i could'nt find a mistake there.
where is the mistake?
bets regards,
jh
Bookmarks