Results 1 to 2 of 2

Thread: Automatic comparisons for custom types stored in QVariant

  1. #1
    Join Date
    Jul 2010
    Location
    Indonesia
    Posts
    83
    Thanked 17 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Maemo/MeeGo

    Question Automatic comparisons for custom types stored in QVariant

    Hi all

    I need to compare objects stored in QVariant automatically without knowing the type.
    The following code explain what problem need to be solved.

    Qt Code:
    1. class A // registered as custom type
    2. {
    3. A(const QVariant& variant);
    4. A& operator=(const QVariant& variant);
    5. operator QVariant() const;
    6. };
    7.  
    8. class B // registered as custom type
    9. {
    10. B(const QVariant& variant);
    11. B& operator=(const QVariant& variant);
    12. operator QVariant() const;
    13. };
    14.  
    15. class AnotherClass
    16. {
    17. public:
    18. bool operator==(const AnotherClass& other) const
    19. {
    20. // COMPARE THE VALUE
    21. return var == other.var; // <-- compare the address, not the value
    22. }
    23.  
    24. private:
    25. QVariant var; // var may contain A or B
    26. };
    To copy to clipboard, switch view to plain text mode 

    Thanks...
    Last edited by viulskiez; 15th July 2011 at 19:24.
    ~ We are nothing in this universe ~

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Automatic comparisons for custom types stored in QVariant

    Whats the question?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. Storing and reading back template types in QVariant
    By Daniel Dekkers in forum Qt Programming
    Replies: 1
    Last Post: 5th April 2010, 07:40
  2. Meta Types and QVariant
    By kroenecker in forum Qt Programming
    Replies: 4
    Last Post: 26th February 2007, 07:48
  3. QVariant::toString and custom data types
    By Vladimir in forum Qt Programming
    Replies: 2
    Last Post: 16th January 2007, 15:36
  4. Use QVariant with custon data types
    By mcosta in forum Qt Programming
    Replies: 4
    Last Post: 11th January 2006, 14:55
  5. QVariant types support for custom properties
    By Dusdan in forum Qt Tools
    Replies: 9
    Last Post: 11th January 2006, 09:55

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.