Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法锚定到不是父项或同级QML QtQuick的项_Qt_Qml_Qtquick2 - Fatal编程技术网

无法锚定到不是父项或同级QML QtQuick的项

无法锚定到不是父项或同级QML QtQuick的项,qt,qml,qtquick2,Qt,Qml,Qtquick2,我正在使用QML开发python桌面应用程序 我的QML文件中有以下内容: SplitView { anchors.fill: parent orientation: Qt.Horizontal Rectangle { color: "#272822" id: cameraRectangle width: window.width / 2 Item { //more stuff

我正在使用QML开发python桌面应用程序

我的QML文件中有以下内容:

SplitView {
    anchors.fill: parent
    orientation: Qt.Horizontal
    Rectangle {
        color: "#272822"
        id: cameraRectangle
        width: window.width / 2
        Item {
           //more stuff
        }
        Item {
            Rectangle {
                anchors.top: cameraRectangle.bottom
            }
        }
    }
    Rectangle {
      //Rectangle info.
    }
}
我得到一个错误,qmlrectangle:无法锚定到不是父项或同级项的项。在我进行锚定的线路上。顶部:cameraRectangle.底部。我会假设外矩形是内矩形的父矩形

我在网上像这样搜索过:他们似乎没有做任何不同的事情

这可能是我正在使用的QtQuick的版本吗

进口货物如下:

import QtQuick 2.6
import QtQuick.Controls 2.0
import QtQuick.Controls 1.4
import QtQuick.Controls.Material 2.0
import QtQuick.Window 2.0
我感谢你的帮助

SplitView {
    anchors.fill: parent
    orientation: Qt.Horizontal
    Rectangle {
        color: "#272822"
        id: cameraRectangle
        width: window.width / 2
        Item {
           //more stuff
        }
        Item {
            // The parent of this Item is 'cameraRectangle'
            // This Item will be the parent of the Rectangle
            // therefore the Rectangle can't anchor to the 'cameraRectangle'
            // anymore. As you are not doing anything with this Item
            // (so far?) anway, you can just delete it, and everything
            // will be fine.
            Rectangle {
                // The parent of this Rectangle is the Item that wraps it
                // and not the 'cameraRectangle'.
                anchors.top: cameraRectangle.bottom
            }
        }
    }
    Rectangle {
      //Rectangle info.
    }
}

正如错误消息所述:您不能锚定到您的父母以外的“祖先”。您还可以锚定到兄弟姐妹。但既不给他们的孩子,也不给你的孩子,也不给你的任何“祖父母”,叔叔或婶婶-

在项目中包装矩形时,父项就是项目。把这个项目放在周围,它就会工作。