我目前正在为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实例的子级呢?
发布于 2018-08-07 23:07:48
使用setParentItem()
Bar(QQuickItem * parent = 0) : QQuickItem(parent) {
// Generate some config called barConfig
QQuickItem * newChild = FooFactory(barConfig);
newChild->setParentItem(this);
}https://stackoverflow.com/questions/51729812
复制相似问题