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. QTreeView and QFileSystemModel problem
QtWS25 Last Chance

QTreeView and QFileSystemModel problem

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.4k 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.
  • malchM Offline
    malchM Offline
    malch
    wrote on last edited by
    #1

    I am using QTreeView with QFileSystemModel and have some basic stuff working nicely. On initializing the QTreeView I expand the first node (which is mapped to my file system root) to give me a list of all the top level directories on my system.

    However, every item listed is shown as expandable (with children). Even the empty directories.

    After expanding items over a period of time, the QTreeView will eventually update and remove the expansion indicators from the empty top level directories (which is what I want). But it can take a while and some clicking.

    I understand QFileSystemModel examines the disk in a separate thread and I assume it's building its internal structures which seems reasonable. Seems to me it should use a breadth-first .v. depth-first traversal though.

    Anyway, it there some easy method of having it more quickly check only the currently displayed nodes to see if they have at least one child and hiding the expansion indicator if not? No need to recurse through the entire file system -- just one level below the currently display items.

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by Chris Kawa
      #2

      Hi, welcome to devnet.

      It definitely does not traverse entire filesystem. That would take forever, eat all your RAM and literally kill hard drives (especially SSDs). The reason you see those branch indicators is precisely because it does not go inside until you actually open the directory. In that case it looks for children and if there are none it removes the indicator.

      malchM 1 Reply Last reply
      0
      • Chris KawaC Chris Kawa

        Hi, welcome to devnet.

        It definitely does not traverse entire filesystem. That would take forever, eat all your RAM and literally kill hard drives (especially SSDs). The reason you see those branch indicators is precisely because it does not go inside until you actually open the directory. In that case it looks for children and if there are none it removes the indicator.

        malchM Offline
        malchM Offline
        malch
        wrote on last edited by
        #3

        Thanks Chris. This is a good thing :-)

        But I still find the behavior odd.

        1. Start with only the file system root expanded.
        2. Expand an empty directory (/cdrom).
        3. Expand another empty directory (/lost+found).
        4. Expand another empty directory (/media).
        5. Expand another empty directory (/mnt).

        At this point all 4 empty directories are shown as expandable.

        1. Expand a directory with children (/opt).

        This last step forces an update and the expansion indicator is finally removed from all 4 empty directories.

        That doesn't seem wonderful to me. But if that's how it's going to be, I can have my QTreeView derived class check each of the currently displayed directories to see if they contain any children and update the display accordingly. My question is how to do that? And how to do it in a manner that will play nicely with QFileSystemModel?

        I should mention I'm running Qt 5.5 under Linux Mint Xfce 17.3 within a VirtualBox guest on a Win 7 Pro system (just in case this turns out of be a VirtualBox related quirk!)

        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