Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QFileSystemModel Traversal for Serialization
Qt 6.12 LTS is out! See what's new in the release blog

QFileSystemModel Traversal for Serialization

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
5 Posts 3 Posters 835 Views 1 Watching
  • 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.
  • stickabeeS Offline
    stickabeeS Offline
    stickabee
    wrote on last edited by
    #1

    I'm trying to use the QFileSystemModel class to create a data model representing the file system on a remote unit. The intent is for the control application, running on the remote unit, to serialize the QFileSystemModel object, send it via socket to a remote instance of a GUI, and have that GUI display the file system of the remote unit in a TreeView.

    I'm trying to understand how the file system structure is stored in the QFileSystemModel and having a lot of trouble "walking" the file system via the various QModelIndex functions. I don't understand how the parent/child hierarchy is maintained in the model and how to get access to children at a given QModelIndex or model location.

    Is there some example of this being done in a QAbstractItemModel or QFileSystemModel? At this point, I'm not asking for an implementation of serialization/deserialization -- I believe I understand that that's something I'm going to have to create myself, but I can't understand how to "walk" the model in order to serialize/deserialize.

    jsulmJ 1 Reply Last reply
    0
    • stickabeeS stickabee

      I'm trying to use the QFileSystemModel class to create a data model representing the file system on a remote unit. The intent is for the control application, running on the remote unit, to serialize the QFileSystemModel object, send it via socket to a remote instance of a GUI, and have that GUI display the file system of the remote unit in a TreeView.

      I'm trying to understand how the file system structure is stored in the QFileSystemModel and having a lot of trouble "walking" the file system via the various QModelIndex functions. I don't understand how the parent/child hierarchy is maintained in the model and how to get access to children at a given QModelIndex or model location.

      Is there some example of this being done in a QAbstractItemModel or QFileSystemModel? At this point, I'm not asking for an implementation of serialization/deserialization -- I believe I understand that that's something I'm going to have to create myself, but I can't understand how to "walk" the model in order to serialize/deserialize.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @stickabee If you just want to collect a list of all subfolders and files on the remote machine then there is no need for QFileSystemModel. See https://stackoverflow.com/questions/8052460/recursively-iterate-over-all-the-files-in-a-directory-and-its-subdirectories-in

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        Beside the good suggestion of @jsulm, you also have to take into account that QFileSystemModel is asynchronous and will only load data when required to avoid exhausting system resources when going through your hard drive.

        Since it's about showing information remotely, it's a model you should think about to minimize the traffic and the amount of processing required.

        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
        3
        • stickabeeS Offline
          stickabeeS Offline
          stickabee
          wrote on last edited by
          #4

          This sounds good. I like the speed and efficiency of the iterator, so that's a win.

          I'm searching now, but is there a decent way to create a model from something like a StringList or some other container that I would put the paths into, that I could use within a TreeView to display something like a nested directory listing? Something roughly akin to the examples using the QFileSystemModel and TreeView?

          Thanks for the help you've already offered. If I figure out something workable before I get a reply, I'll be back to update the post.

          SGaistS 1 Reply Last reply
          0
          • stickabeeS stickabee

            This sounds good. I like the speed and efficiency of the iterator, so that's a win.

            I'm searching now, but is there a decent way to create a model from something like a StringList or some other container that I would put the paths into, that I could use within a TreeView to display something like a nested directory listing? Something roughly akin to the examples using the QFileSystemModel and TreeView?

            Thanks for the help you've already offered. If I figure out something workable before I get a reply, I'll be back to update the post.

            SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            There's the Simple Tree Model example that you can take inspiration from.

            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
            2

            • Login

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