# rodemo **Repository Path**: szonebit/rodemo ## Basic Information - **Project Name**: rodemo - **Description**: No description available - **Primary Language**: C++ - **License**: MIT - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-03-17 - **Last Updated**: 2026-03-17 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # QtRO RPC Demo 这是一个使用 Qt Remote Objects (QtRO) 实现跨进程 RPC 的演示项目。 ## 项目结构 ``` qtro_rpc_demo/ ├── CMakeLists.txt # CMake 构建配置 ├── interface.rep # QtRO 接口定义文件 ├── server/ # 服务端 │ ├── main.cpp # 服务端入口 │ ├── myinterface.h # 接口实现头文件 │ └── myinterface.cpp # 接口实现 ├── client/ # 客户端 │ └── main.cpp # 客户端入口 └── README.md ``` ## 依赖 - CMake >= 3.10 - Qt 5.3+ (需要包含 RemoteObjects 模块) ## 构建步骤 ### Windows (MSVC) ```bash # 1. 创建构建目录 mkdir build cd build # 2. 配置 CMake (根据你的 Qt 安装路径修改) cmake .. -DCMAKE_PREFIX_PATH=C:/Qt/5.3/msvc2013_64 # 3. 编译 cmake --build . --config Release ``` ### Windows (MinGW) ```bash mkdir build cd build cmake .. -G "MinGW Makefiles" -DCMAKE_PREFIX_PATH=C:/Qt/5.3/mingw482_32 cmake --build . ``` ## 运行 需要打开两个终端: ### 终端 1 - 启动服务端 ```bash cd build # Windows MSVC .\Release\rpc_server.exe # Windows MinGW .\rpc_server.exe ``` ### 终端 2 - 启动客户端 ```bash cd build # Windows MSVC .\Release\rpc_client.exe # Windows MinGW .\rpc_client.exe ``` ## 预期输出 ### 服务端输出 ``` Server started, listening on tcp://127.0.0.1:5555 MyInterface service is now available for remote calls Waiting for client connections... Message set to: "Hello from Client!" getMessage() called, returning: "Hello from Client!" add(10, 20) = 30 ping() called - server is alive! ``` ### 客户端输出 ``` Connected to server successfully! Remote object acquired successfully! ========================================== Calling getMessage()... Server message: "Hello from Server!" Calling setMessage("Hello from Client!")... Calling getMessage() again... Server message now: "Hello from Client!" Calling add(10, 20)... Result of add(10, 20) = 30 Calling ping()... ========================================== All RPC calls completed! ``` ## 接口说明 `.rep` 文件定义了远程接口: | 方法 | 说明 | |------|------| | `setMessage(msg)` | 设置消息 (SLOT) | | `getMessage()` | 获取消息 (SLOT) | | `add(a, b)` | 加法运算 (SLOT) | | `ping()` | 心跳测试 (SLOT) | | `messageChanged(msg)` | 消息变化信号 (SIGNAL) | | `message` | 消息属性 (PROP) | ## 注意事项 1. 确保防火墙允许 5555 端口通信 2. 必须先启动服务端,再启动客户端 3. Qt 5.3 中 RemoteObjects 为技术预览功能,可能需要手动安装