이 페이지에서

시간 클라이언트 애플리케이션

서버의 시간 객체 복사본을 보유하며 시계를 통해 시간을 표시하는 클라이언트입니다.

시간 클라이언트 애플리케이션은 메시지가 표시된 파란색 창을 엽니다. 한 번 클릭하면 시계가 표시되고, 다시 클릭하면 시계 두 개가 표시되며, 이 과정이 반복됩니다. 시계는 Clock.qml에 정의되어 있으며, C++로 구현된 ` Time ` QML 타입을 사용하여 서버의 시간을 바탕으로 시계의 시간을 설정합니다.

두 개의 동기화된 아날로그 시계가 표시된 애플리케이션 창

시간 클라이언트 애플리케이션 실행 전

이 예제를 실행하려면, 타임 서버 애플리케이션이 이 애플리케이션과 동일한 호스트에서 이미 실행 중이어야 합니다. 타임 서버 애플리케이션은 레지스트리 서버를 설정하고 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은 hours 및 minutes 속성을 사용하여 시계를 그립니다.

이 애플리케이션은 "plugins.qml"의 내용을 담은 창을 엽니다. Loader를 사용하여 "plugins0.qml", "plugins1.qml", "plugins2.qml"을 클릭할 때마다 순환하며 서로 다른 내용을 표시합니다.

"plugins0.qml"은 메시지가 포함된 파란색 화면을 표시하는 반면, "plugins1.qml"에서는 사용자 정의 QML 유형인 ` Clock `이 사용되며, `hours` 및 `minutes` 속성은 ` Time`의 `hour` 및 `minute` 속성으로 설정됩니다. "plugins2.qml" 파일은 이와 유사하지만 두 개의 시계를 표시합니다.

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

    }
}

예제 프로젝트 @ code.qt.io

‘시간 서버 애플리케이션’항목도 참조하십시오 .

© 2026 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.