QFileSystemModel Traversal for Serialization
-
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.
-
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.
@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
-
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.
-
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.
-
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.
There's the Simple Tree Model example that you can take inspiration from.