I've been traking this for hours. It must be something simple, it always is. But right now I can't see it.

I am following the http://qt-project.org/doc/qt-4.8/modelview.html]Model/View tutorial and QStandardItemModel class reference, but can't get this to work.

I have a QStandardItemModel derivative class, in the constructor I initialize the model and a root node:

Qt Code:
  1. FtpFileSystemModel::FtpFileSystemModel(QObject *parent) :
  2. {
  3. ftp = new QFtp;
  4. remote_file_list = new QList<QStandardItem*>;
  5. root_item = invisibleRootItem();
  6. root_item->setData("/");
  7. ......
To copy to clipboard, switch view to plain text mode 

But when I try to append a row it segfaults.

Qt Code:
  1. void FtpFileSystemModel::slot_list_info(QUrlInfo url_info)
  2. {
  3. QStandardItem *item = new QStandardItem(url_info.name());
  4. root_item->appendRow(item); // <<<<------HERE IT SEGFAULTS!!!!!!
  5.  
  6. for(int i = 0; i < remote_file_list->count(); i++)
  7. qDebug() << Q_FUNC_INFO << QString("row %1, data()='%2'").arg(item->index().row()).arg(item->data().toString());
  8. }
To copy to clipboard, switch view to plain text mode 

This slot is called when a QFtp member runs list(), and it's purpose is to fill the model with info from the files in the ftp repo.

According to the debug info, there are two rows, I guess one is created by invisibleRootItem() and the other by my setData("/") sentence.

I am sure this is probably due to the fact that I don't completely understand how this model works. But I guess that's for another thread. I would be grateful if anyone can give me a hint on what could be causing this.

Thanks beforehand.