Qt6 protobuf generated files are different to protoc
-
wrote 26 days ago last edited by Poldi 5 Sept 2025, 06:03
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 ? -
wrote 24 days ago last edited by
Here is the system info
Qt 6.8.3 (x86_64-little_endian-lp64 shared (dynamic) release build; by GCC 10.3.1 20210422 (Red Hat 10.3.1-1)) on "xcb"
OS: Ubuntu 24.04.2 LTS [linux version 6.8.0-59-generic] -
wrote 24 days ago last edited by
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
)@Poldi You are not linking Qt protobuf module.
And please format your code properly. -
wrote 23 days ago last edited by
Thanks and apologies
-
1/6