0

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 のメタオブジェクト システムに認識させてください #define Q_STATIC_ASSERT_X(条件、メッセージ) static_assert(bool(条件)、メッセージ) ^

4

0 に答える 0