Qt6 protobuf generated files are different to protoc
-
I have started to convert my cmake file to use Qt6 Protobuf to generate c++ code instead of the installed (Ubuntu) and have run into a few issues
- The file name extension is no longer pb.h and pb.cpp. It's qpb.h and qpb.cpp
- The code that used to compile and run now gives me the following compilation error
No member named 'ParseFromArray' in 'nw::remote::Message'
Part of my header
nw::remote::Message* msg_; QTcpSocket* socket_; qint64 bytes_in_; QByteArray msg_stream_; qint32 msg_type_;
Part of the code
void NetworkRemoteIncomingMsg::SetMsgType() { msg_string_ = msg_stream_.toStdString(); msg_->ParseFromString(msg_string_); Q_EMIT InMsgParsed(); }
-
Hi,
Can you provide a minimal project that shows that issue ?
Which version of Qt are you using ? -
I've moved on from this and have changed my code. One issue I have is that
#include <QProtobufSerializer>
gives this error
fatal error: QProtobufSerializer: No such file or directorycmake is
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Protobuf)
if(Qt6Protobuf_FOUND)
message(STATUS "Using Qt6's Protobuf")
set(Protobuf_LIBRARIES Qt${QT_VERSION_MAJOR}::Protobuf)
else()
message(FATAL_ERROR "Missing Qt Protobuf compiler.")
endif()
set(PROTO_SOURCES RemoteMessages.proto)add_library(lib-networkremote STATIC)
qt_add_protobuf(lib-networkremote
PROTO_FILES ${PROTO_SOURCES}
)target_sources(lib-networkremote PRIVATE
incomingmsg.cpp
incomingmsg.h
outgoingmsg.cpp
outgoingmsg.h
)Include directories
target_include_directories(lib-networkremote PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_SOURCE_DIR}/src
${CMAKE_BINARY_DIR}/src
)Link against required libraries
target_link_libraries(lib-networkremote PRIVATE
${GLIB_LIBRARIES}
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::Network
Qt${QT_VERSION_MAJOR}::Gui
) -
I've moved on from this and have changed my code. One issue I have is that
#include <QProtobufSerializer>
gives this error
fatal error: QProtobufSerializer: No such file or directorycmake is
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Protobuf)
if(Qt6Protobuf_FOUND)
message(STATUS "Using Qt6's Protobuf")
set(Protobuf_LIBRARIES Qt${QT_VERSION_MAJOR}::Protobuf)
else()
message(FATAL_ERROR "Missing Qt Protobuf compiler.")
endif()
set(PROTO_SOURCES RemoteMessages.proto)add_library(lib-networkremote STATIC)
qt_add_protobuf(lib-networkremote
PROTO_FILES ${PROTO_SOURCES}
)target_sources(lib-networkremote PRIVATE
incomingmsg.cpp
incomingmsg.h
outgoingmsg.cpp
outgoingmsg.h
)Include directories
target_include_directories(lib-networkremote PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_SOURCE_DIR}/src
${CMAKE_BINARY_DIR}/src
)Link against required libraries
target_link_libraries(lib-networkremote PRIVATE
${GLIB_LIBRARIES}
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::Network
Qt${QT_VERSION_MAJOR}::Gui
) -