如何通过q​​ml在移动设备中创建新窗口?

时间:2017-02-16 10:36:07

标签: ios qt qml

背景 我正在尝试使用qt创建跨平台应用程序。

解决方案 发现:

        MouseArea {
            id: toOtherViewClicked
            width: 44
            anchors.fill: parent

            onClicked: {
                var component = Qt.createComponent("listOfMaterials.qml")
                var window = component.createObject("secondQML")
                window.show()
            }
        }

问题 它的行为非常奇怪。窗口显示几分钟,但然后它再次返回主窗口。是否有可能以适当的方式展示新窗口?

1 个答案:

答案 0 :(得分:1)

您应该记录Component.onDestruction()

很可能GarbageCollector会擦除您的窗口,因为您没有设置父级 component.createObject()的正确语法将对象(父)作为第一个参数。你传递一个字符串。如果你传递一个对象,很可能是GarbageCollector不会擦除你新创建的窗口,直到父对象被销毁。

使它像:

var window = component.createObject(toOtherViewClicked)
相关问题