Windows+Qt使用gRPC
上篇文章《Windows+VS2017使用gRPC》编译出了Windows下可用的gRPC静态lib库文件,在此基础上要想在Qt上使用,需要使用MSVC2017 64bit构建组件进行构建。

grpc-server
新建基于Widget的Qt工程grpc-server
|
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
#ifndef WIDGET_H
#define WIDGET_H #include <QWidget> #include <iostream> #include <grpcpp/grpcpp.h> #include "../grpcSetting/helloworld.grpc.pb.h" using grpc::Server; // Logic and data behind the server's behavior. class QTextBrowser; public: private slots: private: #endif // WIDGET_H |
|
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
#include "Widget.h"
#include <QVBoxLayout> #include <QTextBrowser> #include <QPushButton> Widget::Widget(QWidget *parent) QVBoxLayout *layout = new QVBoxLayout(this); Widget::~Widget() } void Widget::startServer() ServerBuilder builder; // Wait for the server to shutdown. Note that some other thread must be |
grpc-client
新建基于Widget的Qt工程grpc-client
|
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
#ifndef WIDGET_H
#define WIDGET_H #include <QWidget> #include <iostream> #include <grpcpp/grpcpp.h> #include "../grpcSetting/helloworld.grpc.pb.h" using grpc::Channel; class GreeterClient // Assembles the client's payload, sends it and presents the response back // Container for the data we expect from the server. // Context for the client. It could be used to convey extra information to // The actual RPC. // Act upon its status. private: class QTextBrowser; public: private slots: private: #endif // WIDGET_H |
|
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
#include "Widget.h"
#include <QVBoxLayout> #include <QTextBrowser> #include <QPushButton> Widget::Widget(QWidget *parent) QVBoxLayout *layout = new QVBoxLayout(this); Widget::~Widget() } void Widget::req() } |
Pro文件设置
添加预处理器定义:DEFINES += _WIN32_WINNT=0x0A00
添加链接库以及包含库:这里直接复制过来了,一些冗余的内容可根据实际情况调整
|
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
INCLUDEPATH += $$PWD/../../../grpc_plugs/grpc/include
INCLUDEPATH += $$PWD/../../../grpc_plugs/grpc/third_party/protobuf/src DEPENDPATH += $$PWD/../../../grpc_plugs/grpc/include win32: LIBS += -L$$PWD/../../../grpc_plugs/grpc/.build/Debug/ -lgrpc++ win32: LIBS += -L$$PWD/../../../grpc_plugs/grpc/.build/Debug/ -lgrpc win32: LIBS += -L$$PWD/../../../grpc_plugs/grpc/.build/Debug/ -lgpr win32: LIBS += -L$$PWD/../../../grpc_plugs/grpc/.build/Debug/ -laddress_sorting win32: LIBS += -L$$PWD/../../../grpc_plugs/grpc/.build/third_party/protobuf/Debug -llibprotobufd win32: LIBS += -L$$PWD/../../../grpc_plugs/grpc/.build/third_party/zlib/Debug -lzlibd win32: LIBS += -L'C:/Program Files (x86)/Windows Kits/10/Lib/10.0.17763.0/um/x64/' -lWS2_32 INCLUDEPATH += 'C:/Program Files (x86)/Windows Kits/10/Lib/10.0.17763.0/um/x64' win32:!win32-g++: PRE_TARGETDEPS += 'C:/Program Files (x86)/Windows Kits/10/Lib/10.0.17763.0/um/x64/WS2_32.lib' win32: LIBS += -L'C:/Program Files (x86)/Windows Kits/10/Lib/10.0.17763.0/um/x64/' -lAdvapi32 INCLUDEPATH += 'C:/Program Files (x86)/Windows Kits/10/Lib/10.0.17763.0/um/x64' win32:!win32-g++: PRE_TARGETDEPS += 'C:/Program Files (x86)/Windows Kits/10/Lib/10.0.17763.0/um/x64/Advapi32.lib' win32: LIBS += -L$$PWD/../../../grpc_plugs/grpc/.build/third_party/cares/cares/lib/Debug/ -lcares INCLUDEPATH += $$PWD/../../../grpc_plugs/grpc/.build/third_party/cares/cares/lib/Debug win32:!win32-g++: PRE_TARGETDEPS += $$PWD/../../../grpc_plugs/grpc/.build/third_party/cares/cares/lib/Debug/cares.lib |
运行

参考
- Qt使用GRPC之grpc安装(一)
- Qt使用GRPC之grpc安装(二)
- https://github.com/grpc/grpc/blob/master/BUILDING.md#user-content-windows
- grpc1.18.0 c++ windows visual studio 2017(vs2017)版本编译(入门)
- grpc1.18.0 c++ windows visual studio 2017(vs2017)版本Helloworld示例与解析
附录
MinGW使用VS生成的静态库lib文件时,编译不能通过,会提示:
error: No rule to make target '*.a', needed by '*.exe'. Stop.
可见它需要的时*.a的静态库文件,而无法使用*.lib的静态库文件。
但是,MinGW调用linux生成的静态库.a文件,无法链接成功,也无法使用。
网上流传着这样的资料:
首先,下载安装MSYS2:http://www.msys2.org/
(Download and run the installer - "x86_64" for 64-bit, "i686" for 32-bit Windows)
一路“下一步”就可以安装好MSYS2.
然后运行msys2.exe脚本,执行如下命令:
1、pacman -Syu
2、执行完后,关闭终端,重新打开终端执行:pacman -Su
3、pacman -S git
4、pacman -S mingw-w64-i686-grpc
5、pacman -S mingw-w64-i686-qt5
6、pacman -S mingw-w64-i686-qt-creator
之后就可以在安装的qt creator中添加在msys2/mingw32/lib中的grpc静态库和protobuf静态库!!!然后自己根据官网编写简单的C++工程进行测试,只要你库添加的没问题,测试可以通过。
但是,这个叫MSYS2的类Unix环境安装软件很慢,经常出现安装不成功的问题,很不好使!
Windows+Qt使用gRPC的更多相关文章
- Windows+QT+Eclipse+MinGW搭建QT开发环境详细教程
Windows+QT+Eclipse+MinGW搭建QT开发环境详细教程 一.准备工具: QT-SDK for Windows:http://get.qt.nokia.com/qtsdk/qt-sd ...
- windows qt 使用c++ posix接口编写多线程程序(真神奇)good
一.多线程是多任务处理的一种特殊形式,多任务处理允许让电脑同时运行两个或两个以上的程序.一般情况下,两种类型的多任务处理:基于进程和基于线程.基于进程的多任务处理是程序的并发执行.基于线程的多任务处理 ...
- Windows+Qt+MinGW使用gRPC
本文参考博客文章Qt gRPC 简单应用进行了亲自尝试,特此记录以下过程,为后人提供经验.我的环境:Windows10 x64需要依赖MSYS2环境(一个类Unix环境,包管理器)MSYS2 gith ...
- Windows QT 商业版 试用
You're about to evaluate Qt Enterprise - the cross-platform application and UI framework used to dev ...
- Windows+VS2017使用gRPC
gRPC官方Windows安装说明: Install Visual Studio 2015 or 2017 (Visual C++ compiler will be used). Install Gi ...
- 配置windows qt开发环境
1.解压缩MinGW-gcc440_1.zip.将解压后的文件夹复制至C盘根目录下.2.安装qt-creator-win-opensource-2.5.2.3.安装qt-win-opensource- ...
- windows qt 使用openssl API
1.下载安装openssl http://dl.pconline.com.cn/download/355862-1.html 版本: OpenSSL(Win32) 1.0.1g 2.配置QT项目文件, ...
- windows qt 编译 boost 添加 路径
win32-msvc2015: { contains(QMAKE_HOST.arch, x86):{ INCLUDEPATH += D:\3SDK\boost_1_61_0 LIBS += -LD:\ ...
- Windows Qt 项目中文乱码
在头文件中加入 #if _MSC_VER >= 1600 #pragma execution_character_set("utf-8") #endif
随机推荐
- python3基础学习(1)
python基础内容讲解主要内容: 1.使用编辑器(IDE) 2.第一个“hello world” 3.何所谓“变量” 4.python与其他主流语言输出对比 5.数据类型 6.python用作“计算 ...
- Linux 内存文件系统-ramfs and tmpfs
Linux内存文件系统:可满足高IO的要求 ramdisk: 基于虚拟在内存中的其他文件系统(ex2fs). 挂载方式:mount /dev/ram /mnt/ramdisk ramfs: 物理内存文 ...
- [日常] 解决docker拉取镜像速度慢的问题
将docker修改为国内镜像源 在/etc/docker/daemon.json文件中添加下面参数 此处使用的是中国科技大学的docker镜像源 { "registry-mirrors ...
- 在Rust中,cargo使用国内镜像源
一个编程语言依赖包管理的普通问题. cargo解决得比较优雅. 一,新建$HOME/.cargo/config文件 [source.crates-io] registry = "https: ...
- IOS HTML点击时有背景阴影
在写H5时, IOS上的div点击会出现阴影, 如何去掉阴影呢? 在div的css属性中添加下面一条: -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
- Java实现记事本|IO流/GUI
Java实现记事本 题目 利用GUI实现一个简单的记事本(notepad),即打开文件,文字内容显示在界面上: 允许对文字内容进行编辑,并可以保存到文件. 代码 package notePadExp; ...
- 【Spring JDBC】spring jdbc 介绍(一)
Spring JDBC模块是Spring框架的基础模块之一.在Spring JDBC模块中,所有的类可以被分到四个单独的包: core 核心包:它包含了JDBC的核心功能.此包内有很多重要的类,包括: ...
- Semantic 3D
Semantic 3D 这个数据级别的训练集有一个小BUG,是这个neugasse_station1_xyz_intensity_rgb.7z, 解压之后的名字是station1_xyz_intens ...
- ILRuntime 学习
ILRuntime: https://github.com/Ourpalm/ILRuntime Demo: https://github.com/Ourpalm/ILRuntimeU3D 中文在线文档 ...
- UOS系统 - 国产统一操作系统UOS的基本知识
一.UOS操作系统含义及现状 UOS操作系统与windows不同的是,UOS统一操作系统支持龙芯.申威.华为鲲鹏等一票国产处理器芯片.它的诞生是多家国内科技公司联合孕育的结果,包括中国电子集团.武汉深 ...