win10 下 protobuf 与 qt
2023-09-11 14:22:49 时间
编译环境: win10 x64 编译器 :mingw32 cmake 使用场景:Qt4.8.7
下载 protobuf 最新的代码:https://github.com/google/protobuf
点击 configure
使用默认的 mingw32 即可,前提是把 mingw32/bin 加到环境变量Path里面。
然后,发现出错了 gmock 没有 ,可以直接勾选取消 gmock 也可以GitHub 自己下载 mock 补充到源码 (我这直接不生成测试了)
然后在自己指定的文件夹中生成了如下文件
开始编译 (mingw32-make )是 mingw32/bin 下的exe (此目录已在环境变量Path中了)等待完成即可。
成果就是它了
用 .\protoc.exe --proto_path=SRC --cpp_out=DST SRC/test.proto 生成文件(自己建立 src 和dst 文件夹 test.proto 放到src文件下)
// 指定语法规则 syntax = "proto3"; message Book { string name = 1; int32 pages = 2; float price = 3; } message Student { int32 age = 1; string name = 2; float score = 3; repeated Book arrBook = 4; }
生成 test.pb.h 和 test.pb.cc 建立一个Qt项目测试一下吧
void MainWindow::on_pushButton_clicked() { //GOOGLE_PROTOBUF_VERIFY_VERSION; Book book; Book book2; book.set_name("哈哈shishi"); book.set_pages(32); book.set_price(2.63); //qDebug()<< book.IsInitialized(); string str ; book.SerializePartialToString(&str); book2.ParseFromString(str); qDebug()<<QString::fromUtf8(book2.name().c_str())<< " "<<book2.price()<<" "<<book2.pages(); }
包含生成的头文件
#include "test.pb.h" #include <QDebug> #include <iostream> using namespace std;
配置一下 头文件和库文件
最后就是结果了,收工。
相关文章
- Qt-qt creator 运行 出现 "can not open .... jom for write 解决方案
- Qt-获取EXE版本信息(Qt5+win10)(LPCWSTR、std::wstring)
- Qt对WIN目录的操作(包括子目录)
- QT-Qt显示GIF图片
- QT-在Qt Widgets Application中怎么显示printf的输出内容?
- s3c2410上搭建QT/Embedded4.8.5开发环境(四)--安装intel-x86 X11平台qt库qt-everywhere-opensource-src-4.8.5
- Qt编写可视化大屏电子看板系统1-布局方案
- paip.c++ qt 外部dll共享库的导入以及引用
- Qt Windows打包程序脚本
- Qt计算器的实现
- Qt 渐变 QLinearGradient、 QConicalGradient、QRadialGradient
- Qt 关于QT_BEGIN_NAMESPACE宏的作用
- Qt Quick中的信号与槽
- Qt开发-QT Quick
- Qt开发-QT Widgets
- Qt GUI图形图像开发之QT表格控件QTableView详细使用方法与实例
- Qt 项目中main主函数及其作用
- 【Qt】解决 “ubuntu 中的 qt 编辑器光标变成小黑块”
- Qt之自制MP3播放器
- QT-事件发送函数sendEvent()、postEvent()
- 解决Ubuntu系统安装QT出错的问题:qt.qpa.plugin: Could not load the Qt platform plugin “xcb“ in ““ even though it
- 面试怎么回答:QT和MFC对比
- Qt之Sqlite数据库
- qt 传输图片
- qt交叉编译报错::-1: error: The Qt version is invalid: Qt version is not properly installed,please run make
- QT creator使用(二):Qt项目建立、编译、运行、发布及移植