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:
FtpFileSystemModel
::FtpFileSystemModel(QObject *parent
) :{
remote_file_list = new QList<QStandardItem*>;
root_item = invisibleRootItem();
root_item->setData("/");
......
FtpFileSystemModel::FtpFileSystemModel(QObject *parent) :
QStandardItemModel(parent)
{
ftp = new QFtp;
remote_file_list = new QList<QStandardItem*>;
root_item = invisibleRootItem();
root_item->setData("/");
......
To copy to clipboard, switch view to plain text mode
But when I try to append a row it segfaults.
void FtpFileSystemModel
::slot_list_info(QUrlInfo url_info
) {
root_item->appendRow(item); // <<<<------HERE IT SEGFAULTS!!!!!!
for(int i = 0; i < remote_file_list->count(); i++)
qDebug
() << Q_FUNC_INFO <<
QString("row %1, data()='%2'").
arg(item
->index
().
row()).
arg(item
->data
().
toString());
}
void FtpFileSystemModel::slot_list_info(QUrlInfo url_info)
{
QStandardItem *item = new QStandardItem(url_info.name());
root_item->appendRow(item); // <<<<------HERE IT SEGFAULTS!!!!!!
for(int i = 0; i < remote_file_list->count(); i++)
qDebug() << Q_FUNC_INFO << QString("row %1, data()='%2'").arg(item->index().row()).arg(item->data().toString());
}
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.
Bookmarks