Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] Open file listed in a TreeView

[SOLVED] Open file listed in a TreeView

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 2.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    leandrogs
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • L Offline
        L Offline
        leandrogs
        wrote on last edited by
        #3

        That's the point. How do i retrieve the data from model using the index? :)

        1 Reply Last reply
        0
        • L Offline
          L Offline
          leandrogs
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Are you using a QFileSystemModel ? If you do, it provides getters to retrieve the data you are searching

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved