QAbstractItemMode,如何获得QList< *>来自抽象数据方法的变量

时间:2016-05-29 14:56:52

标签: qt qabstractitemmodel qabstractlistmodel

我有一个包含first,last和sub(QList)的类。例如:

   class DataObject { 
public:
 DataObject(const QString &firstName,
         const QString &lastName,
         const QList<SubObject*>   &sublist):
 first(firstName),
 last(lastName),
 sublist(sublist){}

   QString first;
   QString last;
   QList<SubObject*> sublist;
};

在此代码块中添加QList子列表后,我无法构建应用程序:

QVariant SimpleListModel::data(const QModelIndex &index,
                                        int role) const {
if (!index.isValid())
    return QVariant(); // Return Null variant if index is invalid
if (index.row() > (m_items.size()-1) )
    return QVariant();

DataObject *dobj = m_items.at(index.row());
switch (role) {
case Qt::DisplayRole: // The default display role now displays the first name as well
case FirstNameRole:
    return QVariant::fromValue(dobj->first);
case LastNameRole:
    return QVariant::fromValue(dobj->last);
case SubListRole:
   return QVariant::fromValue(dobj->sublist);   //this error line
default:
    return QVariant();
}

错误是: C:\ Qt \ 5.6 \ mingw49_32 \ include \ QtCore \ qglobal.h:725:错误:静态断言失败:类型未注册,请使用Q_DECLARE_METATYPE宏将其告知Qt的meta-对象系统  #define Q_STATIC_ASSERT_X(条件,消息)static_assert(bool(条件),消息)                                                ^

0 个答案:

没有答案