1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Controls.Material 2.15
import QtQuick.Layouts 1.15
Item {
ExampleService {
id: service
// handle value changes inside the service object
onValueChanged: {
// use value
}
}
Connections {
target: service
// handle value changes with an external Connection
function onValueChanged(value) {
// use value
}
}
ColumnLayout {
anchors {
fill: parent
margins: 10
}
RowLayout {
Layout.fillWidth: true
Button {
id: button
Layout.preferredWidth: 100
enabled: !service.isLoading
text: {
return service.isLoading ? qsTr("Loading...") : qsTr("Fetch")
}
onClicked: function() {
service.fetch(url.text)
}
}
TextField {
id: url
Layout.fillWidth: true
enabled: !service.isLoading
text: qsTr("https://jsonplaceholder.typicode.com/todos/1")
}
}
TextEdit {
id: text
Layout.fillHeight: true
Layout.fillWidth: true
// react to value changes from other widgets
text: service.value
}
}
}
|