Create a child instance of the current object
-
Here below
import QtQuick DocumentWindow { visible: true }
is written: Notice that we do not provide a parent element when creating the new instance using createObject. This way, we create new top level elements. If we had provided the current document as parent to the next, the destruction of the parent window would lead to the destruction of the child windows.
The question is how to create the new instance to be a child of the current window?
-
I went for testing a couple of ways but ended up not knowing how to provide a parent element there.
When buttonnew
is clickednewDocument
function is called:function createNewDocument() { var component = Qt.createComponent("DocumentWindow.qml"); var window = component.createObject(); return window; } function newDocument() { var window = createNewDocument(); window.show(); }
Could you guide me.
-
Here below
import QtQuick DocumentWindow { visible: true }
is written: Notice that we do not provide a parent element when creating the new instance using createObject. This way, we create new top level elements. If we had provided the current document as parent to the next, the destruction of the parent window would lead to the destruction of the child windows.
The question is how to create the new instance to be a child of the current window?
@qcoderpro said in Create a child instance of the current object:
Notice that we do not provide a parent element when creating the new instance using createObject.
Negating this sentence will do what you want.
Do provide a parent element when creating the new instance using createObject. -
@qcoderpro said in Create a child instance of the current object:
Notice that we do not provide a parent element when creating the new instance using createObject.
Negating this sentence will do what you want.
Do provide a parent element when creating the new instance using createObject.I went for testing a couple of ways but ended up not knowing how to provide a parent element there.
When buttonnew
is clickednewDocument
function is called:function createNewDocument() { var component = Qt.createComponent("DocumentWindow.qml"); var window = component.createObject(); return window; } function newDocument() { var window = createNewDocument(); window.show(); }
Could you guide me.
-
I went for testing a couple of ways but ended up not knowing how to provide a parent element there.
When buttonnew
is clickednewDocument
function is called:function createNewDocument() { var component = Qt.createComponent("DocumentWindow.qml"); var window = component.createObject(); return window; } function newDocument() { var window = createNewDocument(); window.show(); }
Could you guide me.
-