You are not logged in.

Dear visitor, welcome to If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.


Sunday, September 27th 2009, 2:45am

get selection's path QTreeView

Good morning everyone :)

after i managed to list the files of a directory into a qtreeview now i want to copy selected item's path and name on a QString

(e.x item1 exists on /var/log/packages i select it in qtreeview and in the -lets say- "pkgName" QString i have '/var/log/packages/item1')
the problem is i just cant get it to work, ive tried various methods but nothink worked.

here's my code:

PHP Source code

 pkgName = (listModel->fileName(treeView->currentIndex())); 

note*: "listModel" is QDirModel

Thank you for your time.



  • "ReadMe" is male

Posts: 58

Location: China

  • Send private message


Monday, September 28th 2009, 6:55am

you should use the functions below of QDirModel:

QFileInfo fileInfo ( const QModelIndex & index ) const

QString fileName ( const QModelIndex & index ) const

QString filePath ( const QModelIndex & index ) const