[Qt-interest] QVariant comparisons and custom types?
Daniel Price
daniel.price at fxhome.com
Mon Sep 13 13:33:40 CEST 2010
This is really crap. I can see no-reason why QVariant cannot call custom operators.
Is it worth raising as a bug/suggestion? I can imagine a lot of people running into this.
> -----Original Message-----
> From: qt-interest-bounces at trolltech.com [mailto:qt-interest-
> bounces at trolltech.com] On Behalf Of Dan Milburn
> Sent: 13 September 2010 12:00
> To: qt-interest at trolltech.com
> Subject: Re: [Qt-interest] QVariant comparisons and custom types?
>
> 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.
> >
> >
> >
> > Any help appreciated!
>
> Hi,
>
> Yes, this is an issue I've run into before as well. It seems like it
> should be possible to extend QMetaType to be able to handle equality in
> a similar way as it deals with the QDataStream operators, but there's
> no
> solution available at the moment that I know of.
>
> The only thing I can think of would be to create your own functions for
> testing QVariant equality which knows about your custom types and
> manually casts the variant and compares equality.
>
> Dan
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
This email is confidential. It may also be privileged or otherwise protected by work product immunity or other legal rules. Errors and Omissions Excluded. If you are not the intended recipient please notify the sender. Please delete the message from all places in your computer where it is stored. You should not copy the email or use it for any purpose or disclose its contents to any other person. To do so may be unlawful. Email is an informal means of communicating and may be subject to data corruption accidentally or deliberately. For this reason it is inappropriate to rely on advice contained in an email without obtaining written confirmation of it first.
FXhome Limited is a limited company registered in England and Wales. Registered number: 04172812. Registered office: The Henderson Business Centre, Ivy Road, Norwich, Norfolk, NR5 8BF, U.K.
More information about the Qt-interest-old
mailing list