2
votes

I use Qt 5.5.0 and Qt Creator 3.4.2 on Mac-book, I want to open second qml on button click, I want to develop application in which login page come and after login control move to next page.

I try suggestion of stackoverflow, but still I face problem to open next qml on button click.

I tried

button2.onClicked:{
                        var component = Qt.createComponent("test.qml")
                        var window    = component.createObject(root)
                        window.show()
        }

How can I create a new window from within QML?

In upper case error come related to root, ReferenceError: root is not defined. I gave root id in test.qml file.

I also tried many more example to solve to develop functionality. Please give brief idea or code to develop this functionality.

2

2 Answers

3
votes

The code below works, Take note of the property status and the function errorString() – they will give you information in debugging (.e.g. "file not found" errors, components not ready, etc).

See these pages for background:
Dynamic QML Object Creation from JavaScript
Component QML Type
Window QML Type

   function createWindows() {
     var component = Qt.createComponent("Child.qml");
     console.log("Component Status:", component.status, component.errorString());
     var window = component.createObject(root, {"x": 100, "y": 300});
     window.show();
    }
0
votes

For this type of ui I'd use [StackView][1] component that allows also animations between transitions. Other solution is to use a Loader component.