Congratulations to our 2022 Qt Champions!

QtQuick 2.0: How to get the content filenames of a directory?

  • I need to get a list of names of all the files contained in the directory. How can I do this? Mean while invented just such a dirty hack:
    [code]import QtQuick 2.0
    import Qt.labs.folderlistmodel 1.0
    Item {
    id: filenames
    signal done()
    property var content: new Array(0)

    ListView {
        visible: false
        model: FolderListModel {
            id: folderModel
            folder: "frames"
        delegate: Item {
            Component.onCompleted: {
                if (index == folderModel.count - 1) done()


  • Please don't do this.
    Instantiating delegates to do this sort of thing is evil.

    You should instead define a "singleton type": which has a Q_INVOKABLE function returning a QStringList, containing the directory contents (something like "Q_INVOKABLE QStringList directoryContents(const QString &path) const") which uses QDirIterator or something similar to enumerate the contents of the directory.


  • how comes that Qt.labs.folderlistmodel is still in labs ?

  • C++ Backend (Singleton) is indeed much more preferable for this and not QML

Log in to reply