0
votes

I have an application which contains ListModel. I have written C++ class derived from QAbstractListModel.

QML List model looks like

// SelectedStepsModel.qml
import QtQuick 2.0

ListModel {
    ListElement{
        step_name:""
        step_icon:""

and, C++ class looks like

class ProductModel : public QAbstractListModel
{
    Q_OBJECT

    Q_PROPERTY(QString product_name READ get_product_name)

public:
    enum {
        StepNameRole = Qt::UserRole,
        StepIconRole,
        ...

In main,

...
        ProductModel* product_model = new ProductModel();
        context->setContextProperty("product_model", QVariant::fromValue(product_model));
...

In one of the files (where QML model gets filled by some functions in QML) I want to replace that logic with newly created model ( as model has all data ).

// some other file

    SelectedStepsModel {
        id: selected_model
    }

    selected_model = product_model

Note, here selected_model is ListModel and product_model is QAbstractListModel. But selected_model = product_model is failing.

Am I doing the right thing else what is the correct way of assigning QAbstractListModel to ListModel.

Thanks in advance.

1
It can't be done, why don't you set product_model directly in view?: View{model: product_model}eyllanesc

1 Answers

1
votes

There's no such thing as "assigning" the models here: either you use the model instance that you declared in QML, or you use the model you provided. Choose one or the other.