slodki
12th May 2010, 09:42
Hi!
I have a problem with my class derived from QAbstractItemModel when I want to delete an item.
I already tried signals layoutChanged() and beginRemoveRows()/endRemoveRows() and have no idea, what can be wrong.
I attached a simple example of my problem.
As you run it, please select the third row. After a few seconds I'm removing the second item and sometimes it causes segfault. The backtrace from GDB looks like this:
(gdb) backtrace
#0 0x0804e667 in AbstractModel::parent(QModelIndex const&) const ()
#1 0x0086660c in ?? () from /usr/lib/libQtGui.so.4
#2 0x00866dcb in ?? () from /usr/lib/libQtGui.so.4
#3 0x00867111 in QItemSelectionModel::qt_metacall(QMetaObject::Call , int, void**) () from /usr/lib/libQtGui.so.4
#4 0x00d17c9a in QMetaObject::metacall(QObject*, QMetaObject::Call, int, void**) () from /usr/lib/libQtCore.so.4
#5 0x00d263d5 in QMetaObject::activate(QObject*, QMetaObject const*, int, void**) () from /usr/lib/libQtCore.so.4
#6 0x00d76d77 in QAbstractItemModel::layoutChanged() () from /usr/lib/libQtCore.so.4
#7 0x0805529b in AbstractModel::qt_metacall(QMetaObject::Call, int, void**) ()
#8 0x00d17c9a in QMetaObject::metacall(QObject*, QMetaObject::Call, int, void**) () from /usr/lib/libQtCore.so.4
#9 0x00d263d5 in QMetaObject::activate(QObject*, QMetaObject const*, int, void**) () from /usr/lib/libQtCore.so.4
#10 0x08054ff9 in AbstractItem::updateModel() ()
#11 0x0804d335 in AbstractItem::operator-=(AbstractItem*) ()
#12 0x0804ddc8 in AbstractItem::update() ()
#13 0x0805505d in AbstractItem::qt_metacall(QMetaObject::Call, int, void**) ()
#14 0x00d17c9a in QMetaObject::metacall(QObject*, QMetaObject::Call, int, void**) () from /usr/lib/libQtCore.so.4
#15 0x00d263d5 in QMetaObject::activate(QObject*, QMetaObject const*, int, void**) () from /usr/lib/libQtCore.so.4
#16 0x00d77aa7 in QTimer::timeout() () from /usr/lib/libQtCore.so.4
My question is: How can I safely delete data and inform the model (and treeview) about this change?
I have a problem with my class derived from QAbstractItemModel when I want to delete an item.
I already tried signals layoutChanged() and beginRemoveRows()/endRemoveRows() and have no idea, what can be wrong.
I attached a simple example of my problem.
As you run it, please select the third row. After a few seconds I'm removing the second item and sometimes it causes segfault. The backtrace from GDB looks like this:
(gdb) backtrace
#0 0x0804e667 in AbstractModel::parent(QModelIndex const&) const ()
#1 0x0086660c in ?? () from /usr/lib/libQtGui.so.4
#2 0x00866dcb in ?? () from /usr/lib/libQtGui.so.4
#3 0x00867111 in QItemSelectionModel::qt_metacall(QMetaObject::Call , int, void**) () from /usr/lib/libQtGui.so.4
#4 0x00d17c9a in QMetaObject::metacall(QObject*, QMetaObject::Call, int, void**) () from /usr/lib/libQtCore.so.4
#5 0x00d263d5 in QMetaObject::activate(QObject*, QMetaObject const*, int, void**) () from /usr/lib/libQtCore.so.4
#6 0x00d76d77 in QAbstractItemModel::layoutChanged() () from /usr/lib/libQtCore.so.4
#7 0x0805529b in AbstractModel::qt_metacall(QMetaObject::Call, int, void**) ()
#8 0x00d17c9a in QMetaObject::metacall(QObject*, QMetaObject::Call, int, void**) () from /usr/lib/libQtCore.so.4
#9 0x00d263d5 in QMetaObject::activate(QObject*, QMetaObject const*, int, void**) () from /usr/lib/libQtCore.so.4
#10 0x08054ff9 in AbstractItem::updateModel() ()
#11 0x0804d335 in AbstractItem::operator-=(AbstractItem*) ()
#12 0x0804ddc8 in AbstractItem::update() ()
#13 0x0805505d in AbstractItem::qt_metacall(QMetaObject::Call, int, void**) ()
#14 0x00d17c9a in QMetaObject::metacall(QObject*, QMetaObject::Call, int, void**) () from /usr/lib/libQtCore.so.4
#15 0x00d263d5 in QMetaObject::activate(QObject*, QMetaObject const*, int, void**) () from /usr/lib/libQtCore.so.4
#16 0x00d77aa7 in QTimer::timeout() () from /usr/lib/libQtCore.so.4
My question is: How can I safely delete data and inform the model (and treeview) about this change?