Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    I don't understand QFileSystemModel architecture.

    General and Desktop
    2
    4
    1365
    Loading More Posts
    • 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.
    • W
      wow505 last edited by

      example :

      my fileSystem structure
      @
      A(driver) row = ???, parent-> ??? , Child -> folderA
      └ folderA : row = 0 , parent -> A(driver), Child -> folderB
      └ folderB : row = 0 , parent -> folderA, Child -> folderC
      └ folderC : row = 0 , parent -> folderB, Child -> NULL????

      C(driver) row = ???, parent-> ??? , Child -> folderE, folderD, folderF
      └ folderE : row = 0, parent-> C(driver) , Child -> NULL???
      └ folderD : row = 1, parent-> C(driver) , Child -> NULL???
      └ folderF : row =2, parent-> C(driver) , Child -> NULL???
      @

      I want to access "folderC" or "folderF" using by QFileSystemModel/QModelIndex

      I Try Coding

      trying ACCESS "FolderC" :
      @

      QFileSystemModel* fileSys = new QFileSystemModel;
      
      fileSys->setRootPath("A:");
      
      QModelIndex driverA = fileSys->index("A:");
      
      QModelIndex FolderA = fileSys->index(0,0,driverA ); //now currentIndex point "FolderA"??
      
      QModelIndex FolderB = fileSys->index(0,0,FolderA ); //now currentIndex point "FolderB"??
      
      QModelIndex FolderC = fileSys->index(0,0,FolderB ); //now currentIndex point "FolderC"????
      

      @

      trying ACCESS "FolderF" :
      @

      QFileSystemModel* fileSys = new QFileSystemModel;

      fileSys->setRootPath("A:");
      
      QModelIndex currentIndex = fileSys->index("C:");
      
      currentIndex = currentIndex.child(2,0); // Now, currentIndex point "FolderF"????
      

      @

      I study already Qt Doc 5.0(QFileSystemModel, QModelIndex, Model and View). but, I don't understand.

      I don't know what to do.. help..

      addition Question

      what does mean QFileSystemModel::setRootPath()??

      example :
      @
      QFileSystemModel* fileSys = new QFileSystemModel;

      fileSys->setRootPath("C:"); // <----- fileSys watching only "C: driver"?????
      @

      1 Reply Last reply Reply Quote 0
      • A
        andre last edited by

        Your first example is nonsense. Calling index twice with the same arguments will give the same result (unless the model changed in the mean time).

        Your second example is close, but not quite it. You are saying that the root directory is A:, and then you want to have the item representing C:. However, C: is a sibling of A:, so C: is not going to show up if A: is your root. As you suspect at the bottom, you can limit what part of the file system QFSM represents (and watches). Just set an empty string instead, or use the classID of MyComputer (if you're on windows) as your root path.

        Note that I think you should not be using the model/view API outside of actually tweaking models, proxies or views. The API is just not ideal for direct use from your application.

        1 Reply Last reply Reply Quote 0
        • W
          wow505 last edited by

          thanks for your suggestion
          In this case, how to access folder or directory??

          I want to some example..

          1 Reply Last reply Reply Quote 0
          • A
            andre last edited by

            [[doc:QDirIterator]] would probably be a good start. But it really depends on what you want to do with the file system. What kind of access do you need?

            1 Reply Last reply Reply Quote 0
            • First post
              Last post