diff options
| author | Thomas Vanbesien <tvanbesi@proton.me> | 2026-02-20 12:59:07 +0100 |
|---|---|---|
| committer | Thomas Vanbesien <tvanbesi@proton.me> | 2026-02-20 13:06:24 +0100 |
| commit | 47227acd25c59a1d4b2961c0e1b1eb879e68adec (patch) | |
| tree | b814869a40def023ebb5d0f35931f848c384f122 /demo/NodePage.qml | |
| parent | 263a055f9b9460e4da747c7e56372e963f72fe68 (diff) | |
| download | BobinkQtOpcUa-47227acd25c59a1d4b2961c0e1b1eb879e68adec.tar.gz BobinkQtOpcUa-47227acd25c59a1d4b2961c0e1b1eb879e68adec.zip | |
Add write support with automatic type coercion to OpcUaMonitoredNode
writeValue() Q_INVOKABLE coerces QML JS types to the exact C++ type
expected by the OPC UA node (auto-detected from DataType attribute via
opcUaDataTypeToQOpcUaType). Handles all scalar types, booleans, and
comma-separated array input. Adds writable property derived from
AccessLevel bits. Demo shows inline TextField + Write button for
writable nodes, "(READ-ONLY)" for others.
Diffstat (limited to 'demo/NodePage.qml')
| -rw-r--r-- | demo/NodePage.qml | 47 |
1 files changed, 42 insertions, 5 deletions
diff --git a/demo/NodePage.qml b/demo/NodePage.qml index 1468817..442a6fd 100644 --- a/demo/NodePage.qml +++ b/demo/NodePage.qml @@ -91,21 +91,28 @@ Page { // Column headers RowLayout { Layout.fillWidth: true - spacing: 0 + Layout.leftMargin: 12 + Layout.rightMargin: 12 + spacing: 12 Label { text: "Identifier" font.bold: true - Layout.preferredWidth: 200 - leftPadding: 12 + Layout.preferredWidth: 160 } Label { text: "Value" font.bold: true + Layout.preferredWidth: 160 + } + Label { + text: "Write" + font.bold: true Layout.fillWidth: true } } Rectangle { + id: separator Layout.fillWidth: true height: 1 color: "#ccc" @@ -128,6 +135,10 @@ Page { id: node nodeId: delegate.modelData monitored: nodePage.StackView.status === StackView.Active + onWriteCompleted: (success, message) => { + var short_id = node.nodeId.substring(node.nodeId.indexOf(";s=") + 3); + nodePage.logFunction(short_id + ": " + message); + } } background: Rectangle { @@ -137,19 +148,45 @@ Page { contentItem: RowLayout { spacing: 12 + + // Column 1: Identifier Label { text: { var idx = node.nodeId.indexOf(";s="); return idx >= 0 ? node.nodeId.substring(idx + 3) : node.nodeId; } - Layout.preferredWidth: 188 + Layout.preferredWidth: 160 elide: Text.ElideRight } + + // Column 2: Live value (always visible) Label { text: node.value !== undefined && String(node.value) !== "" ? String(node.value) : "—" - Layout.fillWidth: true + Layout.preferredWidth: 160 elide: Text.ElideRight } + + // Column 3: Edit area (writable) or READ-ONLY label + TextField { + id: editField + visible: node.writable + Layout.fillWidth: true + placeholderText: "Enter value..." + onAccepted: node.writeValue(text) + } + Button { + id: writeButton + visible: node.writable + text: "Write" + onClicked: node.writeValue(editField.text) + } + Label { + visible: !node.writable + text: "(READ-ONLY)" + color: "gray" + font.italic: true + Layout.fillWidth: true + } } ToolTip.visible: hovered |
