TreeView QML错误 - QVariant :: QVariant(void *)'在这种情况下是私人的

时间:2015-10-16 04:41:40

标签: c++ model qml

我正在尝试为treeView设置模型,(我的模型类继承自QAbstractItemModel)

CardsTreeModel * myModel=new CardsTreeModel(file.readAll());


QObject * pTree = m_pQmlObject->findChild<QObject*>("cardsTreeView");
pTree->setProperty("model", myModel );

并且出现了这样的错误:

qvariant.h:465: error: 'QVariant::QVariant(void*)' is private
     inline QVariant(void *) Q_DECL_EQ_DELETE;
cardchoice.cpp:27: error: within this context
  pTree->setProperty("model", myModel );
                                      ^

请帮我解决这个问题!

1 个答案:

答案 0 :(得分:1)

你的myModel QObject?我在C ++中使用类时遇到同样的问题,记得添加Q_OBJECT和qmake。