Results 1 to 3 of 3

Thread: QVariant custom/user type comparison

  1. #1
    Join Date
    Jan 2007
    Location
    Augsburg, Germany
    Posts
    75
    Thanks
    4
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Question QVariant custom/user type comparison

    Hello,

    as the Qt docs state QVariant does not call the "operator==" when you compare two variants with custom types.

    Is there any way to define a comparison method for these types? I want to put a custom type (boost::smart_ptr) into the QComboBox data which works well for enum's when you cast them to int, otherwise not - and the smart_ptr can't be casted to something else Putting this type into the ComboBox works well but i can't use QComboBox::findData() to find my items again ...

    Qt Code:
    1. QVariant v1 = qVariantFromValue(TestNamespace::TestEnum_TestValue1);
    2. QVariant v11 = qVariantFromValue(TestNamespace::TestEnum_TestValue1);
    3.  
    4. v1 == v11: false
    5. v1 == v1 : true
    To copy to clipboard, switch view to plain text mode 

    Thanks for your help and sorry for the bad english

    Edit:
    One way would be to extend undocumented the QVariant::Handler like it's done in QtGui/qguivariant.cpp, but this can only be done from ::qRegisterGuiVariant() and I don't want to modify QVariant itself. Since Qt is not statically linked and qRegisterGuiVariant and qUnregisterGuiVariant are not exported from QtGui, I could "fake" them but that would be an ugly hack ...
    Last edited by gri; 12th August 2008 at 09:09.

  2. #2
    Join Date
    Jan 2007
    Location
    Augsburg, Germany
    Posts
    75
    Thanks
    4
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QVariant custom/user type comparison

    In attachment: The ugly hack solution ... I don't want to use this one!
    Attached Files Attached Files

  3. #3
    Join Date
    Jan 2007
    Location
    Augsburg, Germany
    Posts
    75
    Thanks
    4
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Talking Re: QVariant custom/user type comparison

    Ok, even if no one cares about this ... I'm posting my solution which is not a good example but acceptable
    Attached Files Attached Files

  4. The following 2 users say thank you to gri for this useful post:

    rikrd (17th September 2010), titetluc (25th April 2012)

Similar Threads

  1. Compile 4.4.0
    By LordQt in forum Installation and Deployment
    Replies: 18
    Last Post: 29th May 2008, 13:43
  2. dummy question(Error)
    By Masih in forum Qt Programming
    Replies: 12
    Last Post: 19th July 2007, 23:38

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.