[Qt-interest] QHash vs python dictionary

Andre Somers andre at familiesomers.nl
Tue May 25 11:16:15 CEST 2010


On 25-5-2010 11:59, M. Bashir Al-Noimi wrote:
>
> Hi All,
>
> Currently I'm learning python for web developing. During my study I 
> leaned about python dictionary 
> <http://en.wikibooks.org/wiki/Python_Programming/Dictionaries> which 
> is very flexible data structure where C++ missed it, but I found that 
> QHash (and QMap) class is similar to it, is it true?
>
>
> On another side, python dictionary defines dynamic dimension (infinite 
> child dictionaries or lists) of data where QHash can't (it's C++ 
> template) so I'm wondering is there any Qt class can deal with dynamic 
> dimension of dictionary?
>
>

Well, you can, actually. If you use QVariantHash (a typedef for 
QHash<QVariant>), you can store basically anything in your hash, 
including another QVariantHash. That would allow you the recursion 
you're after, at the price of dealing with QVariants. Of course you can 
also use other types than QVariantHash of course, if you register them 
for usage with QVariant.

For large data structures, I doubt it would be efficient though. 
QVariant has some overhead.

Perhaps a tree-type structure is more what you are after, but it depends 
on what you want to store in it. The solution above is able to store 
mixed data types (though how you are going to trace what is stored where 
is up to you). If you go for a tree, you can only store a single data 
type, but iterating over it could be faster. Unfortunately, Qt does not 
contain a tree container type, but perhaps you can use tree.hh from 
http://www.aei.mpg.de/~peekas/tree/

André


André
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100525/e6615634/attachment.html 


More information about the Qt-interest-old mailing list