[英]How to add a QQuickItem extension as a child to another QQuickItem extension?
我目前正在為Qt Quick建立C ++工廠。 我需要能夠將工廠生成的子級添加到另一個自定義QQuickItem中,如下所示:
class Bar : public QQuickItem {
Q_Object
Bar(QQuickItem * parent = 0) : QQuickItem(parent) {
// Generate some config called barConfig
QQuickItem * newChild = FooFactory(barConfig);
// Add child here?
}
}
實際上,有一個BarModel
控制着工廠的配置,在這里似乎無關緊要。 那么,如何將newChild
添加為Bar
實例的子代呢?
使用setParentItem()
:
Bar(QQuickItem * parent = 0) : QQuickItem(parent) {
// Generate some config called barConfig
QQuickItem * newChild = FooFactory(barConfig);
newChild->setParentItem(this);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.