Cannot anchor to an item that isn't a parent or sibling QML QtQuick
<p>I'm working on a python desktop app.</p>

<p>And currently have this in my QML file.</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>    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.
        }
    }</code></pre>
</div>
</div>
</p>

<p>I get the error that "QML Rectangle: Cannot anchor to an item that isn't a parent or sibling." On the line where I am doing anchors.top: cameraRectangle.bottom. I would have assumed that the outer rectangle IS a parent of the inner one?</p>

<p>I have searched online like here: <a href="http://doc.qt.io/qt-5/qtquick-visualcanvas-visualparent.html" rel="nofollow">http://doc.qt.io/qt-5/qtquick-visualcanvas-visualparent.html</a> and they don't seem to be doing anything differently?</p>

<p>Could it be the version of QtQuick I am using?</p>

<p>The imports are as follows:</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>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</code></pre>
</div>
</div>
</p>

<p>I appreciate your help.</p>

<pre><code>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.
    }
}
</code></pre>

<p>As the error message stated: you can't anchor to 'ancestors' other than your parent. You can also anchor to siblings. But neither to their children, nor to yours, and not to any of your 'grand-parents', uncles or aunts ;-)</p>

python qt pyqt qml qtquick2