Quantcast
Channel: Qt DevNet forums: Qt Quick 1283365070**
Viewing all articles
Browse latest Browse all 4972

QtQuick2: QAbstractListModel - passing object from C++ to QML

$
0
0
Hello. I have a project, which is well working in Qt 4.8, but I need to port it to the new version of Qt – 5.1. 1. I have a class CControl derived from QObject and having a few properties defined by Q_PROPERTY macro. It is registered wit qmlRegisterType. 2. I have the CListModel class, which derives from QAbstractListModel and from QList<CControl*> and I’m using it to pass data for the list defined in QML. 3. I have defined a role ItemRole (named item). 4. When I access it from QML, I just pass (in data() method) my CControl object like this: return QVariant::fromValue<CControl*>(ctrl); When I try to access the ItemRole from QML like this: property CControl control: item I get an error: Unable to assign ObjectsList_QMLTYPE_102 to CControl.

Viewing all articles
Browse latest Browse all 4972

Trending Articles