Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Cannot get QML FolderListModel to work?
Forum Updated to NodeBB v4.3 + New Features

Cannot get QML FolderListModel to work?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
6 Posts 2 Posters 1.7k 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.
  • DiracsbracketD Offline
    DiracsbracketD Offline
    Diracsbracket
    wrote on last edited by Diracsbracket
    #1

    Hi.
    I'm trying to get a list of .xml files in a folder using FolderListModel but when I use
    folderModel.rowCount(), it always returns 0.

    ApplicationWindow  {
        visible: true
        FolderListModel {
            id: folderModel
            //folder: "qrc:///qml/remotes"
            folder: "file:///" + applicationDirPath + "/remotes"
            nameFilters: ["*.xml"]
            showFiles: true
            showDirs: false
        }
    
        LauncherList {
            id: ll
            anchors.fill: parent
    
            Component.onCompleted: {
                console.debug(folderModel.rowCount())
                console.debug(folderModel.folder)
            }
        }
    }
    

    applicationDirPath is set in main.cpp:

    QQmlApplicationEngine engine;
    engine.rootContext()->setContextProperty("applicationDirPath", QGuiApplication::applicationDirPath());
    

    The output of console.debug(folderModel.folder) shows the correct path, but folderModel.rowCount() always returns 0, so I must be doing something wrong?

    DiracsbracketD 1 Reply Last reply
    0
    • DiracsbracketD Diracsbracket

      Hi.
      I'm trying to get a list of .xml files in a folder using FolderListModel but when I use
      folderModel.rowCount(), it always returns 0.

      ApplicationWindow  {
          visible: true
          FolderListModel {
              id: folderModel
              //folder: "qrc:///qml/remotes"
              folder: "file:///" + applicationDirPath + "/remotes"
              nameFilters: ["*.xml"]
              showFiles: true
              showDirs: false
          }
      
          LauncherList {
              id: ll
              anchors.fill: parent
      
              Component.onCompleted: {
                  console.debug(folderModel.rowCount())
                  console.debug(folderModel.folder)
              }
          }
      }
      

      applicationDirPath is set in main.cpp:

      QQmlApplicationEngine engine;
      engine.rootContext()->setContextProperty("applicationDirPath", QGuiApplication::applicationDirPath());
      

      The output of console.debug(folderModel.folder) shows the correct path, but folderModel.rowCount() always returns 0, so I must be doing something wrong?

      DiracsbracketD Offline
      DiracsbracketD Offline
      Diracsbracket
      wrote on last edited by
      #2

      Update: The model itself seems to work, only the rowCount() method or count properties don't seem to work?

      J.HilkJ 1 Reply Last reply
      0
      • DiracsbracketD Diracsbracket

        Update: The model itself seems to work, only the rowCount() method or count properties don't seem to work?

        J.HilkJ Offline
        J.HilkJ Offline
        J.Hilk
        Moderators
        wrote on last edited by
        #3

        @Diracsbracket
        that is most likly the case, because FolderListModel has no function or property called rowCount
        it has count

        count : int
        
        Returns the number of items in the current folder that match the filter criteria.
        

        LauncherList seems to be a custom QML-Item, maby that one has rowCount property or function, and you confused them ?


        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        DiracsbracketD 1 Reply Last reply
        0
        • J.HilkJ J.Hilk

          @Diracsbracket
          that is most likly the case, because FolderListModel has no function or property called rowCount
          it has count

          count : int
          
          Returns the number of items in the current folder that match the filter criteria.
          

          LauncherList seems to be a custom QML-Item, maby that one has rowCount property or function, and you confused them ?

          DiracsbracketD Offline
          DiracsbracketD Offline
          Diracsbracket
          wrote on last edited by Diracsbracket
          #4

          @J.Hilk
          thanks. I got the rowCount() from the Qt Creator's context help, but I agree it may not be usable in QML. Also, no errors are reported when I use it?. However, I also tried to use the count property, and that one also always returns 0. The ListView I use to test the FolderListModel however correctly shows the files....

          J.HilkJ 1 Reply Last reply
          0
          • DiracsbracketD Diracsbracket

            @J.Hilk
            thanks. I got the rowCount() from the Qt Creator's context help, but I agree it may not be usable in QML. Also, no errors are reported when I use it?. However, I also tried to use the count property, and that one also always returns 0. The ListView I use to test the FolderListModel however correctly shows the files....

            J.HilkJ Offline
            J.HilkJ Offline
            J.Hilk
            Moderators
            wrote on last edited by
            #5

            @Diracsbracket mmh, on completed might be the wrong point in time to check the count property, try the following:

            FolderListModel {
                    id: folderModel
                    folder: "file:///" + applicationDirPath + "/remotes"
                    nameFilters: ["*.xml"]
                    showFiles: true
                    showDirs: false
            
                    onCountChanged: console.log("Count Changed",count)
                }
            

            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            DiracsbracketD 1 Reply Last reply
            0
            • J.HilkJ J.Hilk

              @Diracsbracket mmh, on completed might be the wrong point in time to check the count property, try the following:

              FolderListModel {
                      id: folderModel
                      folder: "file:///" + applicationDirPath + "/remotes"
                      nameFilters: ["*.xml"]
                      showFiles: true
                      showDirs: false
              
                      onCountChanged: console.log("Count Changed",count)
                  }
              
              DiracsbracketD Offline
              DiracsbracketD Offline
              Diracsbracket
              wrote on last edited by Diracsbracket
              #6

              @J.Hilk said in Cannot get QML FolderListModel to work?:

              onCountChanged: console.log("Count Changed",count)

              OK that works... I'm new to QML and the declarative paradigm and I'm affraid it will take a lot of time to get used to it... and to get even simple things to work.

              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