我正在尝试为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 );
                                      ^


请帮我解决这个问题!

最佳答案

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

关于c++ - TreeView QML错误-QVariant::QVariant(void *)'在此上下文中是私有(private)的,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33162689/

10-11 23:19