Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QVariant comparator
Forum Updated to NodeBB v4.3 + New Features

QVariant comparator

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 799 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jasig
    wrote on last edited by
    #1

    Hi,

    I'm declaring a class as given below

    @
    class Foo : public Object
    {
    Q_OBJECT
    public:
    Foo(Object* parent = 0);
    virtual ~Foo();

     void setName(QString name);
     QString name();
    

    private:
    QString m_name;
    };

    inline bool operator==(const Foo& lhs, const Foo& rhs)
    {
    qDebug() << "entered Foo == operator";
    return (lhs.name() == rhs.name());
    }

    inline bool operator<(const NameProperty& lhs, const NameProperty& rhs)
    {
    return lhs.name() < rhs.name();
    }

    Q_DECLARE_METATYPE(Foo*)
    @

    and registered it this way

    qRegisterMetaType<Foo*>();
    QMetaType::registerComparators<Foo*>();

    however the equality operator never get's called when i compare two QVariants that contain Foo*.

    Please advise what I'm doing wrong.

    [edit: added missing coding tags @ SGaist]

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      AFAIK, you are providing comparators for Foo not Foo*, so it's comparing the pointer values.

      On a side note, please provide correct code sample, this one doesn't allow to test your problem

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved