使用 vcpkg 在 Windows 上安装的示例

您可以在 Windows 上使用 vcpkg 安装 Protobuf 和 gRPC™ 相关软件包。

注意:作为 替代方案,您可以手动构建 Protobuf 和gRPC 软件包。Protobuf和gRPC的构建说明可分别查阅。

Windows 安装先决条件:

vcpkg 是一款跨平台的 C/C++ 包管理器。您可以使用vcpkg 安装 Protobuf、gRPC 及其依赖项:

.\vcpkg.exe install protobuf protobuf:x64-windows
.\vcpkg.exe install grpc:x64-windows

注意:我们 建议使用清单模式。该模式使用声明式的 JSON 文件来描述项目的元数据。清单文件必须命名为 vcpkg.json。

最后,您可以构建并运行支持 Qt Protobuf 和gRPC 的基于 Qt 的项目。例如,从已安装的 Qt 版本中运行Magic 8 Ball。该示例要求同时安装这两个软件包,因为Magic 8 Ball 针对应用程序的服务器部分使用了原生 C++ 源代码生成器插件。要启动Magic 8 Ball 示例,需要执行以下步骤:

  • 在“Examples ”部分中找到“Magic 8 Ball”:

    截图显示了 Qt Creator 的“主页”菜单,在“示例”部分,搜索栏中输入了“magic”,并显示了名称为“magic”的示例

  • 在 Qt Creator 的配置设置中选择基于 MSVC 的构建套件:

    显示用于构建该项目的 msvc 工具包的屏幕截图

  • 在Initial Configuration 设置块中,将已安装的 Protobuf 和gRPC 包的路径添加到CMAKE_PREFIX_PATH 环境变量中:

    显示 Qt Creator 中使用 MSVC 构建套件的构建选项的屏幕截图

  • 构建并运行。

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