PDA

View Full Version : QTreeModel->setRootIndex when using QSortFilterProxyModel segfaults



killerwookie99
15th August 2008, 17:13
So this works when I don't use a QSortFilterProxyModel but when I make QTreeView use a QSortFilterProxyModel, the compiled code seg faults...



QTreeView *treeView = new QTreeView();
QDirModel *dirModel = new QDirModel();
QSortFilterProxyModel *proxyDirModel = new QSortFilterProxyModel();

proxyDirModel->setSourceModel(dirModel);
treeView->setModel(proxyDirModel);

// I have tried it both of these ways:
treeView->setRootIndex(dirModel->index("/"));
//treeView->setRootIndex(treeProxyModel->sourceModel()->index("/"));


How can I make this work? Right now it seems like having two QDirModels works without problems when I use one dirmodel and try to do this the right way I run into lots of problems and not a lot of good documentation...:eek:

jacek
16th August 2008, 00:26
Which Qt version do you use?

killerwookie99
16th August 2008, 00:47
Upgraded to 4.4.1 a few days back...

jacek
16th August 2008, 01:22
treeView->setModel(proxyDirModel);

// I have tried it both of these ways:
treeView->setRootIndex(dirModel->index("/"));
//treeView->setRootIndex(treeProxyModel->sourceModel()->index("/"));

You can't give dirModel's indices to the treeView, because it operates on treeProxyModel.

Use:
QModelIndex idx = treeProxyModel->mapFromSource( dirModel->index("/") );
treeView->setRootIndex( idx );

killerwookie99
16th August 2008, 02:42
Sweet thank you!