[SOLVED] QTreeview Double Clicked "The program unexpectedly finished"
-
@takoo
and you did use something else than "e:/" ?
and else exact code? Model is living in mainwin .h and dont run out of scope.
(ps sample leaks view)Hmm. I cant guess sorry.
What Qt version and platform?
-
wrote on 1 Feb 2016, 19:41 last edited by
QT 5.5 Linux mint
Code is here
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); const QString dir( "/home/tako/cocos2d-x/" ); const QString targetDir( dir + "OpenWorld/Classes" ); const QString targetRes(dir+"OpenWorld/Resources"); const QString targetBin(dir+"OpenWorld/bin"); model = new QFileSystemModel; model->setRootPath( targetDir ); filter = new filtermodel( targetDir,targetRes,targetBin); filter->setSourceModel(model); filter->mapToSource(i); ui->treeView->setModel(filter); ui->treeView->setRootIndex(filter->mapFromSource(model->index(dir))); } void MainWindow::on_treeView_doubleClicked(const QModelIndex &index) { i=index; qDebug()<<model->fileName(i); }
-
Hi,
index comes from
filter
not frommodel
. You have to map the index like you did in your setRootIndex call -
wrote on 1 Feb 2016, 21:43 last edited by
Please give me example code .
I writting at the moment from phone -
Do you mean an example of calling
mapToSource
? -
wrote on 1 Feb 2016, 23:16 last edited by
Codes above
-
In the code above, you are trying to use an index from your proxy on your file system model. That's the problem, you have to use mapToSource in order to get the right index.
-
In on_treeView_doubleClicked
-
wrote on 3 Feb 2016, 10:51 last edited by
@SGaist I wrote this code and again I get error("the has unexpectedly finished") ```
void MainWindow::on_treeView_doubleClicked(const QModelIndex &index)
{if(index.isValid())
{
filter->mapToSource(model->index(dir));
qDebug()<<model->filePath(index);
}
} -
@takoo said:
Hi
http://doc.qt.io/qt-5.5/qsortfilterproxymodel.html#mapToSource
it returns a new index. I assume you should use that index.
you still use "old" index filePath(index);QModelIndex mapped=filter->mapToSource(model->index(dir));
model->filePath(mapped); -
wrote on 3 Feb 2016, 11:01 last edited by
hi ```
I get error (QSortFilterProxyModel: index from wrong model passed to mapToSource)
void MainWindow::on_treeView_doubleClicked(const QModelIndex &index)
{if(index.isValid())
{
QModelIndex mapped=filter->mapToSource(model->index(dir));qDebug()<<model->filePath(mapped); }
}
-
oh
maybe its
mapToSource(index) -
wrote on 3 Feb 2016, 11:06 last edited by
Thanks everybody
19/23