I found a situation, where bindings works not as I expected. If I bind variable someVar to some other variable(s) and also add handler onSomeVarChanged, the handler executes before bindings. Thus, using any non-trivial code in handler onSomeVarChanged is potentially dangerious. You can use some component, that has variable binded to someVar and this variable is not updated yet. See example below:
main.qml
import QtQuick 2.3
import QtQuick.Controls 1.2
import QtQuick.Layouts 1.1
ApplicationWindow {
id: window
property var currentDate: null
width: 640
height: 480
onCurrentDateChanged: {
print("window.currentDate = " + currentDate)
print("requestManager.date = " + requestManager.date)
requestManager.requestData()
}
RequestManager {
id: requestManager
date: currentDate
}
Button {
text: "Click Me!"
onClicked: currentDate = new Date
}
}
RequestManager.qml
import QtQuick 2.0
Item {
property var date;
function requestData() {
print("requesting data for date " + date)
}
}
Output (after button click):
qml: window.currentDate = Пт сен 19 13:26:24 2014 GMT+0300
qml: requestManager.date = null
qml: requesting data for date null
↧