iHowell
iHowell

Reputation: 2447

How to add a QQuickItem extension as a child to another QQuickItem extension?

I am currently working on setting up a C++ factory for Qt Quick. I need to be able to add the children generated by the factory to another custom QQuickItem, like this:

class Bar : public QQuickItem {
    Q_Object

    Bar(QQuickItem * parent = 0) : QQuickItem(parent) {
        // Generate some config called barConfig
        QQuickItem * newChild = FooFactory(barConfig);
        // Add child here?
    }
}

While in reality, there is a BarModel governing the config for the factory, that seems to be irrelevant here. So, how would I do add my newChild as a child of the Bar instance?

Upvotes: 0

Views: 665

Answers (1)

eyllanesc
eyllanesc

Reputation: 244301

Use setParentItem():

Bar(QQuickItem * parent = 0) : QQuickItem(parent) {
    // Generate some config called barConfig
    QQuickItem * newChild = FooFactory(barConfig);
    newChild->setParentItem(this);
}

Upvotes: 1

Related Questions