0
votes

I'm trying to set up the model for the treeView,( my model class inherits from QAbstractItemModel)

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


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

And got such errors:

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 );
                                      ^

Help me please to resolve this problem!

1
setProperty takes QVariant as its second parameter. You are passing CardsTreeModel*, which cannot be implicitly converted to QVariant. You may be able to write QVariant::fromValue(myModel). It's not clear what you are trying to achieve though; you seem to think that "model" is some special property name and assigning to it achieves some magical effect.Igor Tandetnik
I sucsessfully set the model in this way in such example: QObject * pList = m_pQmlObject->findChild<QObject*>("devicesList"); m_strListView.append("device"); pList->setProperty("model",m_strListView);Mira
QVariant has a constructor taking QStringList, which is what I imagine m_strListView is. Anyway, what you likely want is something like qobject_cast<QAbstractItemView*>(pTree)->setModel(myModel);Igor Tandetnik
Igor, you gave me the right variant (first, qvariant fromvalue)! Model is transferd, but it seems the treeview in qml is incorrect, ant since i can see the right amount of the rows, it's emptyMira
Well, that means your CardsTreeModel doesn't report the correct data to the view. Time to break out your trusty debugger, I suppose.Igor Tandetnik

1 Answers

1
votes

Is your myModel QObject? I have the same problem using class in C++ remember to add Q_OBJECT and qmake.