[Qt-interest] Slight change in Qt example gives segmentation fault

Gunnar kodapa at taljaren.se
Sun Jan 24 17:46:09 CET 2010


Hello there.

I took the source code for the simpletreemodel example that is supplied with 
Qt 4.5 and compiled it, ran it, it worked fine.

It can be found here:
http://qt.nokia.com/doc/4.5/itemviews-simpletreemodel.html

I thought I understood how it worked, but then I tried to add yet one more 
item to the tree I get a segmentation fault. The only change I've done is to 
add the following two lines to the constructor

 
TreeModel::TreeModel(const QString &data, QObject *parent)
    : QAbstractItemModel(parent)
{
    QList<QVariant> rootData;
    rootData << "Title" << "Summary";
    rootItem = new TreeItem(rootData);
    setupModelData(data.split(QString("\n")), rootItem);

 /* NEW CODE */
    TreeItem* x = new TreeItem(rootData);
    rootItem->appendChild(x);
 /* END NEW CODE */

}

and it gives me a segmentation fault and I can't really figure out  why.
Can someone here help me?



More information about the Qt-interest-old mailing list