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. How to fill QML Combobox with name of files present in a folder
QtWS25 Last Chance

How to fill QML Combobox with name of files present in a folder

Scheduled Pinned Locked Moved Solved QML and Qt Quick
5 Posts 2 Posters 1.6k 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.
  • F Offline
    F Offline
    Foufy
    wrote on last edited by
    #1

    Hi everybody,
    I'm a beginner in QML development, and I have lot of difficulties to understand how to fill a QML ComboBox using a list of file obtained by searching inside a specified folder.
    e.g list all *.wav file present in "./MySound" folder

    Thank you for you help.
    Foufy

    J.HilkJ 1 Reply Last reply
    1
    • F Foufy

      Hi everybody,
      I'm a beginner in QML development, and I have lot of difficulties to understand how to fill a QML ComboBox using a list of file obtained by searching inside a specified folder.
      e.g list all *.wav file present in "./MySound" folder

      Thank you for you help.
      Foufy

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

      Hi @Foufy

      you should take a look at the docs here
      It seems to cover your specific case perfectly.


      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.

      1 Reply Last reply
      2
      • F Offline
        F Offline
        Foufy
        wrote on last edited by
        #3

        Hi and thank you for your answer,
        but how to put the result of the folderlistmodel into the combobox. I not able to do it. I'm a real beginner ;)

        J.HilkJ 1 Reply Last reply
        0
        • F Foufy

          Hi and thank you for your answer,
          but how to put the result of the folderlistmodel into the combobox. I not able to do it. I'm a real beginner ;)

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

          @Foufy pretty straight forward actually:

          import QtQuick 2.9
          import QtQuick.Window 2.2
          import Qt.labs.folderlistmodel 2.1
          import QtQuick.Controls 1.4
          
          Window {
              visible: true
              width: 640
              height: 480
              title: qsTr("Hello World")
          
          
              ComboBox {
                  anchors.centerIn: parent
          
                  width: 200
                  height: 50
          
                  FolderListModel{
                      id:folderModel
                  }
          
                  model:folderModel
                  textRole: 'fileName'
              }
          }
          

          But I had to use google once, as ComboBox has no basic delegate like ListView ,for example, has and my standard approach did not work x).

          Kudos to @p3c0 from this old thread


          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.

          F 1 Reply Last reply
          2
          • J.HilkJ J.Hilk

            @Foufy pretty straight forward actually:

            import QtQuick 2.9
            import QtQuick.Window 2.2
            import Qt.labs.folderlistmodel 2.1
            import QtQuick.Controls 1.4
            
            Window {
                visible: true
                width: 640
                height: 480
                title: qsTr("Hello World")
            
            
                ComboBox {
                    anchors.centerIn: parent
            
                    width: 200
                    height: 50
            
                    FolderListModel{
                        id:folderModel
                    }
            
                    model:folderModel
                    textRole: 'fileName'
                }
            }
            

            But I had to use google once, as ComboBox has no basic delegate like ListView ,for example, has and my standard approach did not work x).

            Kudos to @p3c0 from this old thread

            F Offline
            F Offline
            Foufy
            wrote on last edited by
            #5

            @J.Hilk

            Thank you very much, I forgot to set the textRole property actually

            Thanks again.
            Bye

            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