2015-06-08 150 views
2

假設我們有以下QML代碼:綁定調用順序

import QtQuick 2.4 
import QtQuick.Window 2.0 

Window { 
    id: win 
    width: 800 
    height: 600 


    Rectangle { 
     id: rect 
     width: 100 
     height: 100 
     anchors.centerIn: parent 
     color: "orange" 
     property bool test: false 
     MouseArea { 
      anchors.fill: parent 
      onClicked: { 
       rect.test = true; 
      } 
     } 
    } 

    Item { 
     property bool test: rect.test 
     onTestChanged: { 
      rect.color = "green" 
     } 
    } 
    Item { 
     property bool test: rect.test 
     onTestChanged: { 
      rect.color = "yellow" 
     } 
    } 
} 

在上述例子中有2個綁定項rect的屬性test。在這種情況下,綁定的評估順序是什麼?最重要的是,我可以管理它並設置特定的訂單嗎?

回答

3

訂單未定義。我可以發誓,有在某一階段是對本文檔,但現在,我可以在這裏和那裏找到小引用:

Positioning with Anchors:由於綁定的計算順序是沒有定義

[。 ..]

JavaScript Expressions in QML Documents

如果有一個以上的onCompleted()處理程序在啓動時執行,他們正在滑行S相當於未定義的順序。

+0

謝謝,@Mitch,這也是我所設想的。所以,據我瞭解,有沒有辦法來管理它? – folibis

+0

我不認爲在這種情況下有辦法進行管理。 – Mitch