[Qt-interest] segfault with beginRemoveRows()

Uwe Drechsel vym at InSilmaril.de
Sat Mar 21 11:13:57 CET 2009


Hi,

I am using a QTreeView and a model based on the editabletreemodel
example. Now when I call 

beginRemoveRows (parentIndex, n,n)

before starting to delete a row, beginRemoveRows itself calls
TreeItem::parent() several times for the same object, here is the code:

QModelIndex TreeModel::parent(const QModelIndex &index) const
{
    if (!index.isValid())
        return QModelIndex();

    TreeItem *ti= getItem (index);
    TreeItem *parentItem = ti->parent();

    cout << "TreeModel::parent  ti="<<ti<<" "<<ti->getHeading().toStdString()<<"  pi="<<parentItem<<"  "<<endl;
    if (parentItem == rootItem)
        return QModelIndex();

    return createIndex(parentItem->childNumber(), 0, parentItem);
}


and the output:

TreeModel::parent  ti=0x83b3138 sub a  pi=0x83af1d8  
TreeModel::parent  ti=0x83b3138 sub a  pi=0x83af1d8  
TreeModel::parent  ti=0x83b3138 sub a  pi=0x83af1d8  
TreeModel::parent  ti=0x83b3138 sub a  pi=0x83af1d8  
TreeModel::parent  ti=0x83b3138 sub a  pi=0x83af1d8  
TreeModel::parent  ti=0x83b3138 sub a  pi=0x83af1d8  
TreeModel::parent  ti=0x83b3138 sub a  pi=0x83af1d8  
TreeModel::parent  ti=0x83b3138 sub a  pi=0x83af1d8  
TreeModel::parent  ti=0x83b3138 sub a  pi=0x83af1d8  
TreeModel::parent  ti=0x83b3138 sub a  pi=0x83af1d8  
TreeModel::parent  ti=0x83b3138 sub a  pi=0x83af1d8  
TreeModel::parent  ti=0x83b3138 sub a  pi=0x83af1d8  
TreeModel::parent  ti=0x8350408 Heading  pi=0  

I don't understand why parent() is called several times and finally for
the rootItem, which obviously has no parent and when trying to 

return createIndex(parentItem->childNumber(), 0, parentItem); I get a segfault:

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0xb6d3a9c0 (LWP 6049)]
0x0811979d in TreeItem::childNumber (this=0x0) at treeitem.cpp:60
60          if (parentItem)
(gdb) bt
#0  0x0811979d in TreeItem::childNumber (this=0x0) at treeitem.cpp:60
#1  0x0811b1ef in TreeModel::parent (this=0x8350258, index=@0xbfe44690) at treemodel.cpp:88
#2  0xb71425e8 in QAbstractItemModelPrivate::rowsAboutToBeRemoved () from /usr/lib/libQtCore.so.4
#3  0xb7144c4f in QAbstractItemModel::beginRemoveRows () from /usr/lib/libQtCore.so.4
#4  0x08137629 in VymModel::deleteSelection (this=0x8350258) at vymmodel.cpp:2265
#5  0x08137a2a in VymModel::cut (this=0x8350258) at vymmodel.cpp:1916
#6  0x080bea71 in Main::editCut (this=0xbfe45988) at mainwindow.cpp:2482
...


Any hints what I am missing here? As far as I can see I don't have any
additional calls to beginRemoveRows, which could have caused a segfault
according to Bugtracker...



Thanks
Uwe


P.S.: Qt 4.4.0 on openSUSE 11.1

-- 
355/113 -- Not the famous irrational number PI, but an incredible simulation!"



More information about the Qt-interest-old mailing list