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

C++ QAbstractItemModel派生类没有匹配的函数调用,c++,qt,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.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*’
              ^
公司
类编译
构造函数
代码时:

Company::Company(QObject *parent) : QObject(parent),dep_cache(this,this),search_results(this,this)
{
    // .... some intialization stuff here, unrelated to the error
}
它只发生在父类为
qabstractemmodel
的类中。对于其他类,
QObject
的父类,我使用的初始化列表没有错误。添加初始化列表时出现错误

这就是在公司类中声明搜索结果的方式:

class Company : public QObject {
    ...
    DepList             search_results;
    ...
}
它的构造函数是:

DepList::DepList(QAbstractItemModel *parent,Company* p_company) : QAbstractItemModel(parent)
{
    company=p_company;
}
这里的问题是什么?为什么它只发生在
qabstractemmodel
qabstractemmodel
也是
QObject
的子类,我对
QObject
类中的初始化列表没有问题。我曾想过铸造,但安全吗

公司
是一个
质量对象
-衍生:

class Company : public QObject {
    Q_OBJECT
    ...
    explicit            Company(QObject *parent = 0);
    ...
};
class DepList : public QAbstractItemModel
{
    ...
    explicit DepList(QAbstractItemModel *parent = 0,Company* p_company=0);
    ...
}
但是
DepList
是一个
QAbstractItemModel
派生的:

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

问题是,正如错误消息所说,
Company*
无法转换为
qabstractemmodel*
公司
似乎与
qabstractemmodel
无关,不是吗?@songyuanyao你是对的,不是。但是它的成员
search\u results
是qabstractemodel的一个子类。并且两者都继承了
QObject
。我正在
公司
对象的构造函数中初始化
搜索结果
,我知道您正在通过
search\u results(this,this)
初始化
搜索结果
,它正在调用
DepList
的构造函数,该构造函数要求第一个参数是
qabstractemmodel*
;但是您正在传递
这个
,即
公司*
。那么您希望编译器做什么呢?顺便说一句,传入未完全构造的对象的
这个
指针有点危险。有关详细信息,请参阅和。父项必须是
qabstractemmodel
,但
公司
不是。如果将
Company
更改为继承自
qabstractemmodel
而不是
QObject
,则它将正常工作。