I create MyClass and pass 4 images to QML in main.cpp
class.h
#ifndef MYCLASS_H
#define MYCLASS_H
#include <QDebug>
#include <QObject>
class MyClass : public QObject
{
Q_OBJECT
Q_PROPERTY(QString imagePath READ imagePath WRITE setImagePath NOTIFY pathChanged);
public:
explicit MyClass(QObject *parent = 0);
MyClass(QString path)
{
m_imagePath = path;
}
QString imagePath();
void setImagePath(const QString & path);
signals:
void pathChanged(QString path);
private:
QString m_imagePath;
};
#endif // MYCLASS_H
main.cpp
QApplication app(argc, argv);
app.setWindowIcon(QIcon("qrc:/images/logo.ico"));
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
QList<QObject*> dataList;
dataList.append(new MyClass("/images/images/zaglowek.png"));
dataList.append(new MyClass("/images/images/pilot.png"));
dataList.append(new MyClass("/images/images/uklad_jezdny.png"));
dataList.append(new MyClass("/images/images/nozne_sterowanie.png"));
engine.rootContext()->setContextProperty("myModel", QVariant::fromValue(dataList));
For Now MyClass has only image path, but it will also set state (checked-unchecked) and animation (enable-disable).
I would like to reload this QList ( with another images, states etc. ) when button ( one of three ) is clicked ( TButton.qml ).
How to do it ? Please help.