Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QML FolderListModel + TreeView !== tree view



  • not sure if bug or me being stupid...

    when i go to https://doc.qt.io/qt-5/qml-qtquick-controls-treeview.html and look at the example screenshot
    0_1536827265554_treeview.png
    i see a tree view, with expanding folders. cool, exactly what i want!

    then i try to use that with https://doc.qt.io/qt-5/qml-qt-labs-folderlistmodel-folderlistmodel.htm

    test.qml:

    import QtQuick.Controls 1.4
    import Qt.labs.folderlistmodel 2.11
    
    TreeView {
    	width: 300
    	height: 300
    	model: dirModel
    	TableViewColumn {
    		role: "fileName"
    	}
    	FolderListModel {
    		id: dirModel
    		folder: "/etc"
    	}
    }
    

    but instead the suggested view from the example screenshot, i get:

    qmlscene test.qml
    0_1536826964986_test-qmlscene.png

    • where are those folder triangle icons from the screenshot?! (eg. X11 is a dir)
    • nothing happens when i click a folder!?

    qml test.qml
    0_1536826992762_test-qml.png

    • why is here no entries at all?

    am i doing something wrong?
    bug(s)?

    tested with qt5-declarative 5.11.1 on linux.

    ps. FWIW, this is in virtualbox, and i do get following uncritical? errors on launch:

    libGL error: pci id for fd 12: 80ee:beef, driver (null)
    libGL error: No driver found
    libGL error: failed to load driver: (null)
    


  • Hi, please be aware that so-called FolderListModel is typically a ListModel not TreeModel, it's a linear model and be suitable to make use with ListView.

    The fileSystemModel object mention in the example is not an instance of FolderListModel as you assume.

    As far as I know, there's no pure QML way to get full functionality of TreeView, you have to make your own model as the document of TreeView mentioned:

    Data for each row in the TreeView is provided by the model. TreeView accepts models derived from the QAbstractItemModel class.

    HOWTO: Simple Tree Model



  • ah! so was my mistake to assume that "Folder" in name suggested a tree. and i should have seen the List in FolderListModel :/

    thank you very much for your explanation!

    ps. so what i need is a FolderTreeModel, and as i dont have fun in cross-compiling nor c++, ill try again when such qml type exists in qt ;)


Log in to reply