[Qt-interest] QHash vs python dictionary
Andre Somers
andre at familiesomers.nl
Tue May 25 14:35:55 CEST 2010
On 25-5-2010 15:07, M. Bashir Al-Noimi wrote:
> Hi
>
> On 25/05/2010 11:16 ص, Andre Somers wrote:
>> 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.
> I can't expand QVariantHash by width at runtime because it's a C++
> templatewhere in python I can expand the dictionary in two dimensions
> during insert process without any problem (just like making a tree).
In that case, I think that I misunderstood what you want to achieve, and
so did Sean, I guess. I am not familiar with Python, so it is hard to
imagine what the dimensionality you are talking about is all about.
Could you give a simple code example?
If you want to add a second (third, fourth...) index to a hash, like you
can with C arrays ( a[1][3] ), please note that this is really
equivalent if a bit more elegant than what I described above. It does
not matter if you store the "second-dimension" array/hash/map inside the
first, or if the data structure really is a multi-dimensial beast. That
is just syntactic sugar, and if you insist, you can make a simple
wrapper class around the Qt container classes to make this work.
But perhaps you first need to make clear what is is exaclty that you
want to achieve.
André
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100525/cee2da2c/attachment.html
More information about the Qt-interest-old
mailing list