本文主要是介绍qml报错: QML Frame: Cannot anchor to an item that isn‘t a parent or sibling.,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1、错误一:qrc:/main.qml:30:5: QML Frame: Cannot anchor to an item that isn't a parent or sibling
.
QML的anchor必须定位父级对象或者同级对象,不能定位到其他如:同级对象的子对象。
//main.qml
import QtQuick 2.0
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12
import QtQuick.Controls 1.4ApplicationWindow {id: windowvisible: truewidth: 500height: 320Frame {id: f0Frame {id: f1width: 100height: 100background: Rectangle {color: "red"}// 必须首先设置锚点,然后才能设置margin,否则不生效anchors.left: parent.leftanchors.top: parent.topanchors.leftMargin: 10anchors.topMargin: 10}}Frame {id: f2width: 100height: 100background: Rectangle {color: "green"}anchors.top: f1.bottomanchors.left: f1.rightanchors.leftMargin: 10}
}
运行上述错误,原因就是在f2中锚定位了与其同级对象f0的子对象f1了。
这篇关于qml报错: QML Frame: Cannot anchor to an item that isn‘t a parent or sibling.的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!