我想从C ++连接到对象的Component.onCompleted
信号。我应该使用什么语法?
答案 0 :(得分:0)
因此,您可以使用此代码访问Component.completed和Component.destruction信号:
QObject* attached_component = qmlAttachedPropertiesObject<QQmlComponent>(qml_component);
QObject::connect(attached_component, SIGNAL(destruction()), this, SLOT(onDestruction()));
QObject::connect(attached_component, SIGNAL(completed()), this, SLOT(onCompleted()));
qml_component是您的QML组件指针,'this'是具有onDestruction和onCompleted插槽的对象。 也许这是一个黑客但现在它的工作原理(QT 5.8 VS2013)
答案 1 :(得分:0)
一种解决方案是从QML调用C ++函数:
Component.onCompleted:Qml_utils.connect_qmlobject(this)
C ++代码
Q_INVOKABLE void qml_utils::connect_qmlobject(QObject*obj) {
//do something with QML QObject:
connect(obj, SIGNAL(destroyed(QObject*)),
this,SLOT(disconnect_qmlobject(QObject*)));
}