[Qt-interest] Qt-based Tree container?

Andre Somers andre at familiesomers.nl
Thu Oct 29 08:45:26 CET 2009


Hi Alex,

Thanks for your input.

Malyushytsky, Alex wrote:
> Qt does not provide Tree-like container.
> Main purpose of QT is to provide portable code mostly related to the GUI.
> At least advanced data handling seems beyond QT goals.
>   
Well... I think Qt has developed to something way beyond a GUI toolkit. 
To name a few non-GUI area's: networking, database access, XML handing, 
sound handling, multi-threading, scripting... Nokia is not marketing Qt 
as GUI toolkit, but as an application and UI framework. That is quite a 
bit broader.
There are already several very usefull container implementations in Qt, 
and I really don't see why a tree structure would be much more complex 
than a hash structure, for instance. It is not *that* advanced... Also, 
there are already some tree structures to be found here and there: 
QObject hierarchy (as mentioned above), but also for instance 
QTreeWidget with QTreeWidgetItem.
> More of that,AFIK stl does not provide such container either.
>   
So? AFAIK, Qt does not try to replace or to duplicate STL.
> You may try to look at the 3rd party libraries if you really need it.
> I don't have a lot of experience with such, but here are few links:
>
> http://tree.phi-sci.com/
> http://stlplus.sourceforge.net/stlplus/docs/ntree.html
> http://www.boost.org/doc/libs/1_36_0/libs/graph/doc/index.html (graph)
>
>   
Thanks. I actually found some of them already. I found (and was later 
also referred to) this posting on STL: 
http://stackoverflow.com/questions/205945/why-does-the-c-stl-not-provide-any-tree-containers. 
I am actually playing around with the first one as we speak, and it is 
not bad. I was just wondering why something like this was not available 
with a Qt API and the documentation that goes with that. It is also 
these existing implementations that make me convinced that it is 
possible to provide a decent implementation that is usable for most 
usecases. Sure, there will always be cases where the provided solution 
does not fit, but that does not mean that a general solution that works 
in a majority of cases is out of the question, I'd say.

> In the most cases you can simply use std::map.
> (Behind the hood most of the stl implementation of std:map use Red-Black tree)
>   
Let me be clear: I am not after a binairy tree implementation. I am 
after an n-ary tree implementation to store my own stuff, and to use as 
a base for item models that contain trees. However often I build them, I 
still find building those quite tricky. That's why I am searching for a 
good general solution that is extensible enough to build nice, flexible 
models.

André





More information about the Qt-interest-old mailing list