[Qt-interest] QVariant comparisons and custom types?
Stephen Kelly
steveire at gmail.com
Mon Sep 13 13:02:40 CEST 2010
Daniel Price wrote:
> Hi List,
>
> I'm trying to use custom types (enums and structs) with QVariant. To cut a
> long story short, I'm storing custom data in the userData field of combox
> box rows. I have an interface that wraps the combox that must set the list
> to the index corresponding to the row with specific data. This interface
> is generic and can't know about the specific custom data being passed in -
> only that it's a variant that matches another variant already in the list.
>
> For reasons that escape me, QVariant's equality operator doesn't call the
> equality operator of custom types. Rather it compares the addresses of the
> data stored. This makes no sense given that all of Qt other container
> classes behave as expected. In what situations would the addresses be the
> same?!
>
> So I need to find a way around this. I've thought about templates or using
> other variant classes (boost any) but I still need to store them inside
> Qt's interface as a QVariant.
>
> The interface needs to be able to compare the contents of the variants
> without having to be hard-coded with all the type cases.
Sounds like you want KDVariantConverter:
http://docs.kdab.net/kdtools/2.2.1/class_k_d_variant_converter.html
Commercial licenses are available.
Note: KDAB is my employer.
All the best,
Steve.
More information about the Qt-interest-old
mailing list