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?
Use setParentItem()
:
Bar(QQuickItem * parent = 0) : QQuickItem(parent) {
// Generate some config called barConfig
QQuickItem * newChild = FooFactory(barConfig);
newChild->setParentItem(this);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.