QVariant comparator

  • Hi,

    I'm declaring a class as given below

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

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

    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();


    and registered it this way


    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]

  • Lifetime Qt Champion


    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

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.