Qt报错:call to constructor of '_ConfigDaoImpl' is ambiguous

发布时间 2023-06-13 11:06:22作者: 3的4次方

Qt报错:call to constructor of '_ConfigDaoImpl' is ambiguous

原因

configform.cpp:4:13: error: call to constructor of '_ConfigDaoImpl' is ambiguous
configdaoimpl.h:16:5: note: candidate constructor
configdaoimpl.h:17:5: note: candidate constructor

解决

发现在ConfigDaoImpl.h中定义的类ConfigDaoImpl可以生成两个无参构造函数,去掉一个就好。

class ConfigDaoImpl : public Dao
{
public:
    ConfigDaoImpl()=default;//去掉
    ConfigDaoImpl(QObject *parent = nullptr);
    ConfigDaoImpl(const QString& tabName,QObject *parent = nullptr);
    QVector<Config> findAll();
    Config findByID(int m_id);
    int deleteByID(int m_id);
    int insert(Config& cfg);
};

还有一种原因是因为自己的类名和QT框架的某个类相同导致重名。