How to create a QQmlComponent from a C++ class

Viewed 32

I am trying to create a QQmlComponent from a C++ class that is subclass of QObject, but I can't figure out how.

Paintable class:

class Paintable : public QQuickPaintedItem
{
    Q_OBJECT
    Q_PROPERTY(QString text READ getText WRITE setText NOTIFY textChanged)
public:
    Paintable(QQuickPaintedItem* parent=nullptr);
protected:
    paint(QPainter* painter);
}

main.cpp:

...
Paintable* paintable = new Paintable();
paintable->setText("Hello World!");
QQmlComponent component = //convert paintable to QQmlComponent here but how?
...
0 Answers
Related