Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QFileSystemModel: include files from subfolders (Qt 5.5.1)
Forum Update on Monday, May 27th 2025

QFileSystemModel: include files from subfolders (Qt 5.5.1)

Scheduled Pinned Locked Moved Unsolved General and Desktop
qfilesystemmodeqt 5.5.1subdirs
15 Posts 2 Posters 7.0k 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.
  • S Offline
    S Offline
    SGaist
    Lifetime Qt Champion
    wrote on 14 Mar 2016, 21:02 last edited by
    #6

    What do you want to use it for ?

    Interested in AI ? www.idiap.ch
    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

    1 Reply Last reply
    0
    • Q Offline
      Q Offline
      qDebug
      wrote on 14 Mar 2016, 22:21 last edited by
      #7

      The goal here is to find text files in a given path and list them in a QListView. If the user clicks on a text file in this list, he should be able to rename it and on a double click to edit the text file. So far so good, i got this covered.

      In some rare cases text files are sorted inside sub directories, one by one - means 20 text files are in 20 sub directories. It is kinda lame to click through all the subs so my idea was to add a button or check box to also include all text files in this given root path.

      The first part was easy and fast for me to accomplish but the second part - including text files from sub directories and add them to the QListView / QFileSystemModel is still a mystery to me. I'm still a Qt beginner, any help is appreciated.

      Thank you!

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 14 Mar 2016, 22:52 last edited by
        #8

        Then a model based on QAbstractListModel that you populate using QDirIterator might be the simple way to go.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • Q Offline
          Q Offline
          qDebug
          wrote on 15 Mar 2016, 02:43 last edited by
          #9

          This is not an option, i rather give up on this and show additional files in a log window or any other way. If the user browses through directories and clicks C: for example, the app will lock for seconds or minutes if no ssd is present.

          Is it really that complicated to include sub directories in QFileSystemModel?

          1 Reply Last reply
          0
          • S Offline
            S Offline
            SGaist
            Lifetime Qt Champion
            wrote on 15 Mar 2016, 21:28 last edited by
            #10

            Just to be sure I understand you correctly, your additional folders should act like a QFileSystemModel with a QFileSystemModel ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • Q Offline
              Q Offline
              qDebug
              wrote on 15 Mar 2016, 23:49 last edited by
              #11

              I just need them all together in the listview widget i got for files from the QFileSystemModel and i need the paths to the files so i can open them for edit.

              1 Reply Last reply
              0
              • Q Offline
                Q Offline
                qDebug
                wrote on 16 Mar 2016, 13:55 last edited by
                #12

                I sort of found a solution that works. On button click i change the listview model from QFileSystemModel to QStringListModel and call a function and use QDirIterator to add filenames to a QStringList. It needs additional code but if QFileSystemModel can't be set to a recursive directory mode, i don't have a lot of options, i guess.

                Is there any better solution?

                Thanks!

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 16 Mar 2016, 22:07 last edited by
                  #13

                  Like I wrote, QFileSystemModel is optimized to avoid filing up your memory with everything it can find on the hard drive.

                  Your use case really sounds like QDirIterator is a better choice to retrieve the information you want.

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • Q Offline
                    Q Offline
                    qDebug
                    wrote on 16 Mar 2016, 23:23 last edited by qDebug
                    #14

                    I don't need all the files from a hard drive, just the files in all the sub directories inside directory. For example on Windows: C:\text-files\2016*.txt and all the *.txt files from C:\text-files\2016\1*.txt C:\text-files\2016\2*.txt and so on. I don't need files from C:\Windows or C:\Programs or ...

                    Edit: Editor is removing \ before * so please imagine them there! ^^

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on 16 Mar 2016, 23:33 last edited by
                      #15

                      That I understood. That's why I think that QDirIterator is a better tool to find what you want on your drive.

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0

                      15/15

                      16 Mar 2016, 23:33

                      • Login

                      • Login or register to search.
                      15 out of 15
                      • First post
                        15/15
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved