タイムクライアントアプリケーション
サーバーから時刻オブジェクトのレプリカを保持し、時刻を時計で表示するクライアント。
タイムクライアントアプリケーションは、メッセージとともに青いウィンドウを開きます。一度クリックすると時計が表示されます。もう一度クリックすると2つの時計が表示され、それを繰り返します。時計はClock.qmlで定義され、C++で実装されたTime
QML型を使って、サーバーの時刻を使って時計の時刻を設定します。
タイムクライアントアプリケーションを実行する前に
この例を実行するには、Time Serverアプリケーションがこのアプリケーションと同じホスト上ですでに実行されている必要があります。これはレジストリサーバーを設定し、MinuteTimerSimpleSource
クラスのサブクラスのインスタンスをホストします。実行されていない場合は、ウィンドウにエラーメッセージが表示されます。
REP ファイルを使用したリモート・オブジェクトの定義
このアプリケーションの親ディレクトリにある REP ファイル "timemodel.rep "は、両方のアプリケーショ ンで使用されるヘッダーファイルの生成に使用されます。このアプリケーションでは、生成された "rep_timemodel_replica.h "ファイルによって、MinuteTimerReplica
、MinuteTimer
のレプリカ、およびその他の関連クラスが定義されています。
TimeModel クラス
plugin.hとplugin.cppにあるTimeModel
クラスはQMLタイプのTime
を実装しています。このクラスは "local:registry "というURLを使ってlocalhost上のレジストリ・サーバーにコンタクトし、MinuteTimerReplica
というレプリカを取得し、そのシグナルに接続します。プロパティは自動的に更新されます。
QMLタイプ
"Clock.qml "で定義されたQMLは、時、分のプロパティを使って時計を描画します。
アプリケーションは "plugins.qml "の内容でウィンドウを開きます。plugins0.qml"、"plugins1.qml"、"plugins2.qml "をクリックするたびに、ローダーを使って表示内容を切り替えます。
plugins0.qml "はメッセージ付きのブルースクリーンを表示しますが、"plugins1.qml "ではカスタムQMLタイプのClock
、プロパティはTime
。 plugins2.qml "も同様ですが、2つの時計を表示します。
import QtRemoteObjects import QtQuick import TimeExample // import types from the plugin Rectangle { width: 200 height: 400 color: "blue" Clock { id: clock1 anchors.top: parent.top Time { // this class is defined in C++ id: time node: node } Node { id: node registryUrl: "local:registry" } hours: time.hour minutes: time.minute valid: time.state == Time.Valid } }
タイムサーバーアプリケーションも参照 。
© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.