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
随机推荐
- DevOps 工程师成长日记系列二:配置
原文地址:https://medium.com/@devfire/how-to-become-a-devops-engineer-in-six-months-or-less-part-2-config ...
- 从立创EDA,Gratipay看中文编程开发环境和推广运营的一个趋势
前不久听说立创EDA,对比之前的讨论: 适合中文用户的编程语言和IDE, 侧重于现有语言/IDE不具备的特性 · Issue #11 · program-in-chinese/overview,觉得颇 ...
- Spark的Monitoring
一.启动历史页面监控配置: $ vi spark-defaults.conf spark.eventLog.enabled true spark.eventLog.dir hdfs://hadoop0 ...
- mean shift聚类算法的MATLAB程序
mean shift聚类算法的MATLAB程序 凯鲁嘎吉 - 博客园 http://www.cnblogs.com/kailugaji/ 1. mean shift 简介 mean shift, 写的 ...
- JS阻止冒泡和取消默认事件(默认行为)
本文链接:http://caibaojian.com/javascript-stoppropagation-preventdefault.html 阻止事件冒泡 function(e){ if( e ...
- lua 6 函数
定义: function max(num1, num2) local result = 0 if (num1 > num2) then result = num1; else result = ...
- angular设置全局变量,修改监听变量
创建service.module.ts import { NgModule, ModuleWithProviders } from '@angular/core'; import { SomeShar ...
- Educational Codeforces Round 78 (Rated for Div. 2) 题解
Shuffle Hashing A and B Berry Jam Segment Tree Tests for problem D Cards Shuffle Hashing \[ Time Lim ...
- oracle序列相关
一. oracle中如何实现一列的规律增长呢(通常是指number类型的列)? 这就需要借助序列来实现了; 1. 什么是序列? 可以理解为序列是一组sql语法创建出来的函数, 该函数中定义 好 ...
- stm32配置led
前言:我们学习一门新语言的时候都是先从hello world入门,stm32也有自己的入门方式,那就是流水灯的配置. 在配置之前我们需要先配置好编译环境,我们需要手动修改头文件中的一些内容. 1.首先 ...