[Qt-interest] QVariant comparisons and custom types?

Daniel Price daniel.price at fxhome.com
Mon Sep 13 10:15:36 CEST 2010


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!


Daniel Price
Software Engineer
FXhome Limited

daniel.price at fxhome.com<mailto:daniel.price at fxhome.com>
http://fxhome.com


________________________________
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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100913/5d9a8d08/attachment.html 


More information about the Qt-interest-old mailing list