QML can I call destroy for "statically" created Dialog?

76 Views Asked by At

It is ok to do the following:

Component {
    id: editDialogComp
    Dialog {
        onClosed: destroy()
    }
}

But what if I have

SpecialDialog.qml:

Item {
    Dialog {
        anchors.fill: parent
        ...
        onClosed: destroy() // is it ok?
    }
}

And then create the component:

QQmlComponent component(engine, "SpecialDialog.qml");
auto* object = component.beginCreate(engine->rootContext());
component.completeCreate();
QQmlEngine::setObjectOwnership(object, QQmlEngine::JavaScriptOwnership);

In the code above, if comment the destroy() call, the new Dialog will be created every time one opens the form and all the dialogs will not be destroyed until app exit.

0

There are 0 best solutions below