Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to build QT with GRPC

How to build QT with GRPC

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 4.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    wei chi
    wrote on last edited by wei chi
    #1

    here is my .pro file

    QT += core gui
    
    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    
    TARGET = basler_opt_3
    TEMPLATE = app
    
    # The following define makes your compiler emit warnings if you use
    # any feature of Qt which has been marked as deprecated (the exact warnings
    # depend on your compiler). Please consult the documentation of the
    # deprecated API in order to know how to port your code away from it.
    DEFINES += QT_DEPRECATED_WARNINGS
    
    # You can also make your code fail to compile if you use deprecated APIs.
    # In order to do so, uncomment the following line.
    # You can also select to disable deprecated APIs only up to a certain version of Qt.
    #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
    
    INCLUDEPATH += /usr/local/lib \
                   /usr/local/bin
    
    #/opt/pylon5/include
    # /usr/local/include/opencv3 \
    LIBS += `pkg-config opencv --libs`
    LIBS += -L/opt/pylon5/lib64 -Wl,-E -lpylonbase -lpylonutility -lGenApi_gcc_v3_1_Basler_pylon -lGCBase_gcc_v3_1_Basler_pylon
    #LIBS += `opt/pylon5/bin/pylon-config --libs`
    LIBS += -L/usr/local/lib -lgrpc++ -lgrpc -lgpr -lz -lprotobuf -lgrpc++_reflection -ldl
     #`pkg-config grpc grpc++ protobuf --libs)`
    CONFIG += console
    QMAKE_CXXFLAGS+= -I/opt/pylon5/include
    #QMAKE_CXXFLAGS+= -I/usr/include/opencv
    
    #$(shell /opt/pylon5/bin/pylon-config --cflags) \
       #              $(shell pkg-config --cflags opencv)
    
    QMAKE_LFLAGS+= $(shell /opt/pylon5/bin/pylon-config --libs-rpath)
    
    SOURCES += \
            main.cpp \
            mainwindow.cpp \
        rs232.cpp \
        optrs232.cpp \
        secdialog.cpp \
        imagethread.cpp \
        settingdialog.cpp \
        helloworld.pb.cc \
        helloworld.grpc.pb.cc \
        grpcserver.cpp \
        grpcthread.cpp
    
    HEADERS += \
            mainwindow.h \
        rs232.h \
        optrs232.h \
        global.h \
        BaslerHeader.h \
        baslercam.h \
        secdialog.h \
        imagethread.h \
        settingdialog.h \
        helloworld.pb.h \
        helloworld.grpc.pb.h \
        grpcserver.h \
        grpcthread.h
    
    
    FORMS += \
            mainwindow.ui \
        secdialog.ui \
        settingdialog.ui
    
    RESOURCES += \
        resource.qrc
    

    Here is the error i am confuse.
    ee5b37f2-c54e-4994-88ef-302e82dbd7d8-image.png !
    Absolutely, I am no idea how to solve this, hope someone can help me.
    Thanks

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      Where does SearchService come from ?

      INCLUDEPATH's content looks wrong as you are passing folders containing dlls and binaries.

      Your LIB content is likely also wrong.

      qmake already provides support for pkg-config. You should check the documentation.

      By the way, a .pro file is not a bash script so your call to pkg-config does not do what your think it does.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2
      • W Offline
        W Offline
        wei chi
        wrote on last edited by
        #3

        Thank for your reply.
        However, I do not understand clearly.
        I am working on ubuntu.
        My .proto file is below.
        Therefore, I get four files helloworld.grpc.pb.cc, helloworld.grpc.pb.h, helloworld.pb.cc, and helloworld.pb.h from the .proto file.

        syntax = "proto3";
         
        	message SearchRequest
        	{
        		uint32 ImgRows_req=1;
        		uint32 ImgCols_req =2;
        		bytes ImgData_req=3;
        		uint32 ImgType_req=4;
        		uint32 ImgSize_req=5;
                string Commands=6;
        		string Msg_req=7;
        		uint32 Image_Index=8;
        
        	}
         
        	message SearchResponse
        	{
        		
        		uint32 ImgRows_rsp= 1;
        		uint32 ImgCols_rsp =2;
        		bytes ImgData_rsp=3;
        		uint32 ImgType_rsp=4;
        		uint32 ImgSize_rsp=5;
                string ErrorMsg_rsp=6;
                string Msg_rsp=7;
        		uint32 Threshold_rsp=8;
        
        
        	}
         
        	service SearchService {
          		rpc Search (SearchRequest) returns (SearchResponse);
            }
        
        

        SearchService is come from helloworld.grpc.pb.cc.
        I inlcude helloworld.grpc.pb.h in my grpcserver.h.
        However, error "SearchService has not been declared" is still exist.

        // Generated by the gRPC C++ plugin.
        // If you make any local change, they will be lost.
        // source: helloworld.proto
        
        #include "helloworld.pb.h"
        #include "helloworld.grpc.pb.h"
        
        #include <functional>
        #include <grpcpp/impl/codegen/async_stream.h>
        #include <grpcpp/impl/codegen/async_unary_call.h>
        #include <grpcpp/impl/codegen/channel_interface.h>
        #include <grpcpp/impl/codegen/client_unary_call.h>
        #include <grpcpp/impl/codegen/client_callback.h>
        #include <grpcpp/impl/codegen/method_handler_impl.h>
        #include <grpcpp/impl/codegen/rpc_service_method.h>
        #include <grpcpp/impl/codegen/server_callback.h>
        #include <grpcpp/impl/codegen/service_type.h>
        #include <grpcpp/impl/codegen/sync_stream.h>
        
        static const char* SearchService_method_names[] = {
          "/SearchService/Search",
        };
        
        std::unique_ptr< SearchService::Stub> SearchService::NewStub(const std::shared_ptr< ::grpc::ChannelInterface>& channel, const ::grpc::StubOptions& options) {
          (void)options;
          std::unique_ptr< SearchService::Stub> stub(new SearchService::Stub(channel));
          return stub;
        }
        
        SearchService::Stub::Stub(const std::shared_ptr< ::grpc::ChannelInterface>& channel)
          : channel_(channel), rpcmethod_Search_(SearchService_method_names[0], ::grpc::internal::RpcMethod::NORMAL_RPC, channel)
          {}
        
        ::grpc::Status SearchService::Stub::Search(::grpc::ClientContext* context, const ::SearchRequest& request, ::SearchResponse* response) {
          return ::grpc::internal::BlockingUnaryCall(channel_.get(), rpcmethod_Search_, context, request, response);
        }
        
        void SearchService::Stub::experimental_async::Search(::grpc::ClientContext* context, const ::SearchRequest* request, ::SearchResponse* response, std::function<void(::grpc::Status)> f) {
          ::grpc::internal::CallbackUnaryCall(stub_->channel_.get(), stub_->rpcmethod_Search_, context, request, response, std::move(f));
        }
        
        void SearchService::Stub::experimental_async::Search(::grpc::ClientContext* context, const ::grpc::ByteBuffer* request, ::SearchResponse* response, std::function<void(::grpc::Status)> f) {
          ::grpc::internal::CallbackUnaryCall(stub_->channel_.get(), stub_->rpcmethod_Search_, context, request, response, std::move(f));
        }
        
        void SearchService::Stub::experimental_async::Search(::grpc::ClientContext* context, const ::SearchRequest* request, ::SearchResponse* response, ::grpc::experimental::ClientUnaryReactor* reactor) {
          ::grpc::internal::ClientCallbackUnaryFactory::Create(stub_->channel_.get(), stub_->rpcmethod_Search_, context, request, response, reactor);
        }
        
        void SearchService::Stub::experimental_async::Search(::grpc::ClientContext* context, const ::grpc::ByteBuffer* request, ::SearchResponse* response, ::grpc::experimental::ClientUnaryReactor* reactor) {
          ::grpc::internal::ClientCallbackUnaryFactory::Create(stub_->channel_.get(), stub_->rpcmethod_Search_, context, request, response, reactor);
        }
        
        ::grpc::ClientAsyncResponseReader< ::SearchResponse>* SearchService::Stub::AsyncSearchRaw(::grpc::ClientContext* context, const ::SearchRequest& request, ::grpc::CompletionQueue* cq) {
          return ::grpc::internal::ClientAsyncResponseReaderFactory< ::SearchResponse>::Create(channel_.get(), cq, rpcmethod_Search_, context, request, true);
        }
        
        ::grpc::ClientAsyncResponseReader< ::SearchResponse>* SearchService::Stub::PrepareAsyncSearchRaw(::grpc::ClientContext* context, const ::SearchRequest& request, ::grpc::CompletionQueue* cq) {
          return ::grpc::internal::ClientAsyncResponseReaderFactory< ::SearchResponse>::Create(channel_.get(), cq, rpcmethod_Search_, context, request, false);
        }
        
        SearchService::Service::Service() {
          AddMethod(new ::grpc::internal::RpcServiceMethod(
              SearchService_method_names[0],
              ::grpc::internal::RpcMethod::NORMAL_RPC,
              new ::grpc::internal::RpcMethodHandler< SearchService::Service, ::SearchRequest, ::SearchResponse>(
                  std::mem_fn(&SearchService::Service::Search), this)));
        }
        
        SearchService::Service::~Service() {
        }
        
        ::grpc::Status SearchService::Service::Search(::grpc::ServerContext* context, const ::SearchRequest* request, ::SearchResponse* response) {
          (void) context;
          (void) request;
          (void) response;
          return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, "");
        }
        
        

        INCLUDEPATH is where the header files are. like. grpc pylon
        And LIBS is where the .so files are. like the grpc .so -L/usr/local/lib -lgrpc++ -lgrpc -lgpr -lz -lprotobuf -lgrpc++_reflection -ldl
        Did I miss anything?
        I appreciate your kind assistance.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          What version of protoc are you using ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • semlanikS Offline
            semlanikS Offline
            semlanik
            wrote on last edited by
            #5

            Hi, this https://github.com/semlanik/qtprotobuf might be useful for you

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved