Skip to content

Instantly share code, notes, and snippets.

@t-artikov
Created November 14, 2017 20:06
Show Gist options
  • Save t-artikov/f58130f21821c0863a9d7dc27103d2e1 to your computer and use it in GitHub Desktop.
Save t-artikov/f58130f21821c0863a9d7dc27103d2e1 to your computer and use it in GitHub Desktop.
// Calculator.qml
import QtQuick 2.0
QtObject {
property real a
property real b
readonly property real sum: a + b
signal overflow()
onSumChanged: {
if(sum > 10000000) overflow()
}
function reset() {
a = 0
b = 0
}
}
//-------------------------------
// server.qml
import QtQuick 2.0
import Rpc 1.0
RpcServer {
port: 5656
object: Calculator {}
}
//-------------------------------
// client.qml
import QtQuick 2.0
import QtQuick.Controls 1.0
import QtQuick.Layouts 1.0
import Rpc 1.0
ApplicationWindow {
title: "client"
width: 640
height: 480
visible: true
RpcClient {
id: rpc
address: "127.0.0.1"
port: 5656
}
readonly property QtObject calculator: rpc.object
ColumnLayout {
anchors.centerIn: parent
RowLayout {
Binding {
target: calculator
property: "a"
value: txtA.text || 0
}
Binding {
target: calculator
property: "b"
value: txtB.text || 0
}
TextField {
id: txtA
}
Label {
text: "+"
}
TextField {
id: txtB
}
Label {
text: "="
}
TextField {
text: calculator ? calculator.sum : ""
}
}
Button {
text: "reset"
onClicked: if(calculator) calculator.reset()
}
Label {
id: overflowLabel
Connections {
target: calculator
onOverflow: overflowLabel.text = "overflow!"
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment