Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
[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.
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
That's the point. How do i retrieve the data from model using the index? :)
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() + "\\"
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