没有匹配函数调用QAbstractItemModel派生类

时间:2017-01-15 03:32:11

标签: c++ qt

我收到此错误:

/MyApp/company.cpp:3: error: no matching function for call to ‘DepList::DepList(Company*, Company*)’
 Company::Company(QObject *parent) : QObject(parent),dep_cache(this,this),search_results(this,this)
                                                                                                  ^
/MyApp/company.h:14: In file included from ../../../../MyApp/company.h:14:0,
/MyApp/company.cpp:1: from ../../../../MyApp/company.cpp:1:
/MyApp/deplist.h:34: candidate: DepList::DepList(QAbstractItemModel*, Company*)
     explicit DepList(QAbstractItemModel *parent = 0,Company* p_company=0);
/MyApp/deplist.h:34: note:   no known conversion for argument 1 from ‘Company*’ to ‘QAbstractItemModel*’
              ^

编译constructor类的Company代码时:

Company::Company(QObject *parent) : QObject(parent),dep_cache(this,this),search_results(this,this)
{
    // .... some intialization stuff here, unrelated to the error
}

它只发生在父级为QAbstractItemModel的类中。对于其他类,QObject的父级我正在使用初始化列表而没有错误。添加初始化列表时出现错误。

这是在公司类中声明search_results的方式:

class Company : public QObject {
    ...
    DepList             search_results;
    ...
}

它的构造函数是:

DepList::DepList(QAbstractItemModel *parent,Company* p_company) : QAbstractItemModel(parent)
{
    company=p_company;
}

这里有什么问题,为什么它只发生在QAbstractItemModelQAbstractItemModel也是QObject的子项,我对QObject类中的初始化列表没有任何问题。我考虑过铸造,但它会安全吗?

CompanyQObject - 派生的:

class Company : public QObject {
    Q_OBJECT
    ...
    explicit            Company(QObject *parent = 0);
    ...
};

DepListQAbstractItemModel - 派生的:

class DepList : public QAbstractItemModel
{
    ...
    explicit DepList(QAbstractItemModel *parent = 0,Company* p_company=0);
    ...
}

0 个答案:

没有答案