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);
};
class B // registered as custom type
{
B(const QVariant& variant);
B& operator=(const QVariant& variant);
};
class AnotherClass
{
public:
bool operator==(const AnotherClass& other) const
{
// COMPARE THE VALUE
return var == other.var; // <-- compare the address, not the value
}
private:
};
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
};
To copy to clipboard, switch view to plain text mode
Thanks...
Bookmarks