Quote Originally Posted by d_stranz View Post
Well, generally the easiest way to implement a model to be used by a QTreeView is to implement an external, standalone data structure that contains the data you want to map to the model, using a plain old C++ data class / structure. Each of the items you want to place in the tree model contains a pointer to some node in this data tree. Thus, your model's parent() method will retrieve the pointer to the corresponding data node, go up a level in the data tree to its parent, then creates (using createIndex) a new QModelIndex where the row is the parent's index in its parent's (i.e. the grandparent of the current node) child list and the column is always zero. Set the internal data pointer of the new model index to the value of the parent node pointer and you're done.

Likewise, the index() method calls createIndex() with the row and column number requested, and assigns the data tree pointer to the index's internal pointer.

If you aren't getting a three-membered list (file, size, permission), then you are either 1) returning the wrong columnCount() for the node in the tree or 2) inserting the size and position as children of the file item (maybe by setting their parent() incorrectly in the model).
Thank you so much. That was really helpful.

At the end of the day, a tree is just a tree, but I guess my previous experience with other languages played a trick or two on me this time, instead of being of help. That and the fact that QModelIndex() drives me to panic since I landed into the Qt view/model stuff as a whole some months ago :P

Right now, the code is in a state that I get output from the class into the view. That's a good starting point. I am not completely reliant about my index() and parent() method, but I am in the right track, at last.

In the right side of the image you can see the FtpFileSystemModel in action. Right now it can only show files. Hopefully it will learn to do some more stuff, given enough time

20140522.180439.jpg

Again, thank you