Question

I want to build a tree with items which are always automatically sorted under a tree node when adding, renaming, and doing other operation. std::set seems a good candidates for my data container. However, it seems Qt tree favors vectors or QList (a pointer vector) since the tree items are accessed, inserted, or removed via their indices or row numbers. I am using std::distance like function to calculate index for an item in the set. But I think it is very slow (not tested). Any good way to let Qt tree model work with std::set, or may I need to use vectors for my data, or develop a new container to do it? Thanks a lot!

Find an answer: use boost::container::flat_set. Thanks.

Was it helpful?

Solution

QSet is not a good idea for this purpose. As well as not providing index-based access, it's completely unordered, that is there are absolutely no guarantees on the order of traversal. There's no sensible way that can be made to work with a Qt item model. You'd be much better off just using QList and ensuring the values are unique yourself.

OTHER TIPS

You should probably use QTreeView , and subclass QAbstractItemModel this way you can use any data source you want

see this question : Creating Qt models for tree views

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top