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 用于持久化特性的基本存储