Qt报错:no match for ‘operator==‘ (operand types are ‘xxx‘ and ‘const xxx‘)

Qt报错error: no match for ‘operator==’ 提示:

F:\Qt\mingw49_32\include\QtCore\xxx.h:999: error: 
	no match for 'operator==' (operand types are 'xxx' and 'const xxx')
         if (i->t() == t)
                    ^

解决方法:

在对应的自定义数据类型中重载"=="运算符

bool operator==(const 类名 &other) const
    {
        return (类名.xxx== other.xxx);
    }

示例:

class Dog
{
public:
    Dog();
    ~Dog();
    QString m_sName;
    QString m_sAge;
    bool operator==(const Dog &other) const
    {
        return (Dog.m_sName == other.m_sName
        				|| Dog.m_sAge == other.m_sAge);
    }
};

你可能感兴趣的:(Qt客户端开发技巧,qt,开发语言,c++)