Qt Remote Objects QML 類型

QML 類型的 Qt Remote Objects 提供構建遠程對象網絡所需的幫手塊。通常,它們用於結閤構成特定網絡的自定義注冊復製類型。

例如,考慮以下 .rep 文件:

class MyType {
    PROP(QString myProp="Hello World")
};
					

可以將生成復本注冊成 QML 類型:

qmlRegisterType<MyTypeReplica>("custom",1,0,"MyTypeReplica")
					

然後使用 QML 結閤基本類型 Node:

import QtQuick 2.0
import QtRemoteObjects 5.12
import custom 1.0
Item {
    MyTypeReplica {
        id: myType
        node: Node { registryUrl: "local:registry" }
    }
    Text { text: myType.myProp }
    MouseArea {
        anchors.fill: parent
        onClicked: myType.pushMyProp("Updated Text")
    }
}
					

Note that by default you cannot directly assign to a replica property, but rather use a push function. This is due to the potential problems that arise from the mix of declarative programming and asynchronous updates. Specifically, we want to avoid issues like the following:

myType.myProp = "Updated Text"
console.log(myType.myProp) // logs "Hello World", as the new text has not yet been round-tripped
					

The QML types in this module can be imported into your application using the following import statement in your .qml file:

import QtRemoteObjects 5.12
					
					

QML 類型

Node Qt Remote Objects 網絡節點
SettingsStore 用於持久化特性的基本存儲