[SOLVED] Open file listed in a TreeView
-
How can i open a file in treeview with double click?
I have a list of folders and files in a treeView and i need to authorize users to open a file when double clicked a item.
I've tried this:
@connect(this->ui->treeView, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(loadFromWorkspace(QModelIndex)));@
But i don't know how to use this index who is passed by parameter to loadFromWorkspace function. -
Hi,
Use the index to retrieve the data from your model i.e. "fileInfo":http://qt-project.org/doc/qt-4.8/qfilesystemmodel.html#fileInfo from QFileSystemModel. Other models offer other possibilities.
Hope it helps
-
Thank you for your help. You made me think and i found the proper solution. here follows the solution:
@QString filePath = this->workspacepath + "\\"
+ index.parent().data().toString() + "\\"
+ index.data().toString();QFile file(filePath);@
Now i have my file opened and i can made everything i want :D
-
Are you using a QFileSystemModel ? If you do, it provides getters to retrieve the data you are searching