[Qt-qml] Use model en c++

marvin42 tourde_a at live.fr
Mon Oct 18 10:57:57 CEST 2010


Hi,

I want use model, in new type QML

example:

NewType {
       id: 42
       size: 42
       model: MyModel {}
}

But I don't use variable "model" of type QVariant,
I try convert in QObject or QAbstractListModel or QAbstractItemModel

example:

class NewType : public QDeclarativeItem
{
Q_PROPERTY(QVariant model READ model WRITE setModel NOTIFY modelChanged)

public:

      QVariant model() const;
      void setModel(const QVariant &);
}

In function setModel


QObject *object = qvariant_cast<QObject *>(model);
QAbstractItemModel* m = qobject_cast<QAbstractItemModel *>(object);
QAbstractListModel * i = qobject_cast<QAbstractListModel *>(object);


But don't convert type, so don't use my model.


How we create model in c++ ?
Do you want create delagate

Thank

-- 
marvin42



More information about the Qt-qml mailing list