PDA

View Full Version : Automatic comparisons for custom types stored in QVariant



viulskiez
15th July 2011, 17:27
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.


class A // registered as custom type
{
A(const QVariant& variant);
A& operator=(const QVariant& variant);
operator QVariant() const;
};

class B // registered as custom type
{
B(const QVariant& variant);
B& operator=(const QVariant& variant);
operator QVariant() const;
};

class AnotherClass
{
public:
bool operator==(const AnotherClass& other) const
{
// COMPARE THE VALUE
return var == other.var; // <-- compare the address, not the value
}

private:
QVariant var; // var may contain A or B
};

Thanks...

high_flyer
18th July 2011, 14:07
Whats the question?