QTAndroid protobuf with QT creator
-
Hi, can you guide me on how to add protobuf in QTandroid application
I tried with process given on this link
https://stackoverflow.com/questions/44773136/google-protobuf-and-android-ndkbut still after adding myproject..pb.cc and myproject.pb.h files in my QT creator application it gives errors for non-virtual member function marked as final , undefined reference etc can you please help me with this?
-
Hi and welcome to devnet,
What exact error are you getting ?
Did you try to build your project for your desktop machine ?
Can you provide a minimal example project that people can attempt to build ?
-
@sgaist hi and thank you for your response ,
Actully I am trying to build my project for android phones (QTAndroid),
My main Question is how to compile my .proto file for QTAndroid which gives .pb.cc and .pb.h in return
I followed this link :
https://github.com/protocolbuffers/protobuf/issues/5279after creating source tree I run below command to generate pb.cc and pb.h :
./protoc --cpp_out=./ myfile.protobut protoc file is not generating pb.cc and pb.h file.
'My proto file code is given below:
syntax = "proto2";
package DOP;
// Defines request that a tag/anchor may receive via UART or BT SPP
enum ReqType {
DFUMODE = 0; // Device must switch to DFU mode and reset
SETUWBCFG = 1; // Set UWB network configuration parameters
GETUWBCFG = 2; // Get current UWB network configuration parameters
}// Defines types of responses to a request message
enum RespType {
ACK = 0; // ACK the successfull execution of a request
NACK = 1; // Request was not executed
RESPUWBCFG = 2; // Current UWB configuraion data
}message Request {
required uint32 req_type = 1; // Must be one of ReqType
required uint32 req_ID = 2; // A number that would help the requesting side to indentify the reply later
}message Response {
required uint32 resp_type = 1; // Must be one of RespType
required uint32 req_ID = 2; // The ID of the request to which we are replying// TODO: Add field for response parameters (like UWB configuration)
}
message Cycle {
message Imu { required uint32 x = 1; required uint32 y = 2; required uint32 z = 3; } message Tag { required uint32 tagid = 1; // ID of the Tag which replied to the corresponding Anchor (current Tag). Number must be unique inside the network - 65536 max number of tags. required uint32 tof1 = 2; // Time-of-flight from the corresponding Anchor to the current Tag, calculated during tsync1 and tsync2 slots accordingly. In in uS. required uint32 tof2 = 3; optional uint32 vbat = 4; // Battery voltage, 6bit, 25mV resolution, range between 2.650 V 4.250 V optional uint32 rssi = 5; // P46: DW1000 User Manual 2.03. Practical range -99...-67 dBm per 0.5dBm optional uint32 sensor = 6; // Data from internal sensors, For pressure sensor - Range 0 to 1.28bar steps 0.02bar optional Imu acc_data = 7; // Linear x,y, z acceleration from the Tag IMU optional Imu gyro_data = 8; // x,y, z data from the Tag IMU optional Imu mag_data = 9; // } // Data collected by an Anchor message Anchor { required uint32 anchorid = 1; // ID of the Anchor which polled the Tag whos data are included in this message (current Anchor). required Tag tag_data = 2; } required uint32 cycleid = 1; // ID of the current offload cycle. Wraps up to 0 when reaching the maximum. repeated Anchor anc_data = 2;
}
-
One thing you can to is install the protobuf compiler package from your distribution and use that one. It will generate the files that you can then use for your project.
-
@amol said in QTAndroid protobuf with QT creator:
I want to cross compile it with Android then I can us it
From the issue you pointed before, have you check this comment? It says it succeeded, and it describes all the tool versions for its environment (Clang, NDK, Qt, etc.)
-
@pablo-j-rogina yes I used it but it's for clang I want for armabi-7
-
@amol said in QTAndroid protobuf with QT creator:
it's for clang I want for armabi-7
It looks you're mixing things up.
Clang is a compiler (tool) while armabi-7 is a processor architecture (platform)
A compiler creates an executable program for a particular platform.As you can see from that comment, Clang should allow you to build the required protobuf file(s) for your platform
-
protoc just generate files in the programming language you choose. There's nothing special here, as I already suggested, install the protoc compiler from your distribution and generate the file with it.
-
-
Did you add the
LIBS +=
statement in your .pro file to link to the library ?
-
@sgaist said in QTAndroid protobuf with QT creator:
LIBS +=
My proto file look like this:
#-------------------------------------------------
Project created by QtCreator 2016-03-22T07:38:29
#-------------------------------------------------
QT += core gui bluetooth
CONFIG += c++11greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = BLETester
TEMPLATE = appSOURCES += main.cpp
acp.pb.cc
dfuservice.cpp
mainwindow.cpp
bleinterface.cpp
utils.cppHEADERS += mainwindow.h
acp.pb.h
bleinterface.h
dfuservice.h
lib-qt-qml-tricks/src/qqmlhelpers.h
lib-qt-qml-tricks/src/qqmlhelpers.h
utils.hFORMS += mainwindow.ui
win32:INCLUDEPATH += "$$PWD\google"
RESOURCES +=
resources.qrcandroid{
INCLUDEPATH += F:\QT_android\compile\protobuf-3.9.1\src
LIBS += -L"F:\QT_android\compile\protobuf-3.9.1\src\protobuff_android"
-lprotobuf
-lprotobuf-lite
-lprotoc
}Turn off ALL warning for the project
win32:CONFIG += warn_off
contains(ANDROID_TARGET_ARCH,armeabi-v7a) {
ANDROID_EXTRA_LIBS =
$$PWD/../protobuf_android/libprotobuf.so
$$PWD/../protobuf_android/libprotobuf-lite.so
$$PWD/../protobuf_android/libprotoc.so
}DISTFILES +=
acp.proto -
Are you sure you have built protobuf for the correct architecture ? 32 vs 64 bit for example ?
-
@sgaist said in QTAndroid protobuf with QT creator:
distribution
@sgaist said in QTAndroid protobuf with QT creator:
protoc just generate files in the programming language you choose. There's nothing special here, as I already suggested, install the protoc compiler from your distribution and generate the file with it.
yes
as you said, i have installed protobuf compiler on Linux 64 bit and from that only I am generating pb.cc and pb.h filesIs that correct?
-
Start by just building the protobuf related files so you ensure that you have that stuff working correctly. I would even start first by building for your desktop OS. That way you ensure that this part is working correctly before going forward with Android.
-
@amol said in QTAndroid protobuf with QT creator:
I used protobuf but it is for Windows or Linux
Ok, so you're somehow experienced with that technology.
For me that I'm not, could you please explain how to use protobuf in a general way, and I guess that in the process you might figure out what you're doing differently or not yet doing for Android?
In addition, when working with a 3rd party library or files that you want to use in a Qt application for Android the basic requirement is that the library is compiled for any of the Android platforms (usually arm6, arm7 and lately arm8) and that process is usually carried on separately from Qt Creator via the NDK (talking about a C++ library or files). Once you have the (shared) objects created with the NDK you place them in a proper location within the Qt project folder structure and then Qt Creator is finally able to create the Android app and deploy to the device configured in your kit.
So talking about protobuf it couldn't be that different. You need to create with NDK whatever components are required (either a .so or files .cc and .h) and then add such files to your Qt project