타임 서버 애플리케이션
연결된 클라이언트와 시간 객체를 공유하는 서버입니다.
시간 서버 애플리케이션은 ` MinuteTimer ` 객체를 인스턴스화하여 연결된 모든 시간 클라이언트 애플리케이션과 공유합니다.

REP 파일을 사용하여 원격 객체 정의하기
예제의 상위 디렉터리에 있는 REP 파일 "timemodel.rep"은 두 애플리케이션 모두에서 사용하는 헤더 파일을 생성하는 데 사용됩니다. 이 애플리케이션의 경우, 생성된 "rep_timemodel_source.h" 파일은 ` MinuteTimerSource` 클래스와 ` MinuteTimer` 구현을 위해 상속해야 할 클래스, 그리고 기타 관련 클래스들을 정의합니다.
TimeModel 클래스
timemodel.h 및 timemodel.cpp에 정의된 TimeModel 클래스는 공유할 시간 객체를 구현합니다. 이 클래스는 QBasicTimer 를 사용하여 timerEvent 멤버 함수를 호출함으로써 시간이 올바르게 업데이트되도록 보장합니다.
void MinuteTimer::timerEvent(QTimerEvent*)
{
QTime now = QTime::currentTime();
if (now.second()== 59&& now.minute()== time.minute()&& now.hour()== time.hour()) {
// 시간 틱 전환 시점을 아슬아슬하게 놓쳤으므로, 강제로 전환하고 0.5초 더 대기
time = time.addSecs(60);
timer.start(60500, this);
} else {
time = now;
timer.start(60000-time.second()*1000, this);
}
qDebug()<<"Time"<<time;
setHour(time.hour());
setMinute(time.minute());
emit timeChanged();
}TimeModel 인스턴스 공유하기
QRemoteObjectHost 및 QRemoteObjectRegistryHost 인스턴스는 객체를 호스팅하고 이를 찾을 수 있는 레지스트리를 갖기 위해 생성됩니다. 그런 다음 MinuteTimer 객체가 생성되며, 이는 QRemoteObjectRegistryHost 객체의 enableRemoting 멤버 함수를 사용하여 공유됩니다.
int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
#if defined(Q_OS_UNIX) || defined(Q_OS_LINUX) || defined(Q_OS_QNX)
signal(SIGINT, &unix_handler);
#elif defined(Q_OS_WIN32)
SetConsoleCtrlHandler((PHANDLER_ROUTINE)WinHandler, TRUE);
#endif
QRemoteObjectHost node(QUrl(QStringLiteral("local:replica")),QUrl(QStringLiteral("local:registry")));
QRemoteObjectRegistryHost node2(QUrl(QStringLiteral("local:registry")));
MinuteTimer timer;
node2.enableRemoting(&timer);
Q_UNUSED(timer)
return app.exec();
}‘Time Client Application’항목도 참조하십시오 .
© 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.