Important: Please read the Qt Code of Conduct -

I don't understand QFileSystemModel architecture.

  • 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;
    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;

    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"?????

  • 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.

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

    I want to some example..

  • [[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?

Log in to reply