2015-11-28 61 views
1

我在Mac-book上使用Qt 5.5.0和Qt Creator 3.4.2,我想打开第二个qml上的按钮点击,我想开发应用程序,其中登录页面来并在登录后控制移动到下一页。如何打开第二个qml页面上按钮点击

我尝试堆栈的建议溢出,但我仍然面临问题打开下一个qml按钮单击。

我试图

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?

在上壳体误差来与根,的ReferenceError:根没有定义。我在test.qml文件中给出了root ID。

我也尝试了更多的例子来解决开发功能。请提供简要的想法或代码来开发此功能。

+0

http://stackoverflow.com/help/mcve – Mitch

回答

2

以下作品的代码,以财产status和功能errorString()的注意 - 他们会给你调试信息(.e.g“找不到文件”的错误,组件没有准备好,等)。

见这些网页背景:
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

对于这种类型的UI我会使用[StackView][1]组件,还允许转换之间的动画。其他解决方案是使用Loader组件。