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. Qt6 protobuf generated files are different to protoc
Forum Updated to NodeBB v4.3 + New Features

Qt6 protobuf generated files are different to protoc

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 171 Views 1 Watching
  • 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.
  • P Offline
    P Offline
    Poldi
    wrote last edited by Poldi
    #1

    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

    1. The file name extension is no longer pb.h and pb.cpp. It's qpb.h and qpb.cpp
    2. 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();
    }
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote last edited by
      #2

      Hi,

      Can you provide a minimal project that shows that issue ?
      Which version of Qt 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
      • P Offline
        P Offline
        Poldi
        wrote last edited by
        #3

        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]

        1 Reply Last reply
        0
        • P Offline
          P Offline
          Poldi
          wrote last edited by
          #4

          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 directory

          cmake 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
          )

          jsulmJ 1 Reply Last reply
          0
          • P Poldi

            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 directory

            cmake 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
            )

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote last edited by
            #5

            @Poldi You are not linking Qt protobuf module.
            And please format your code properly.

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • P Offline
              P Offline
              Poldi
              wrote last edited by
              #6

              Thanks and apologies

              1 Reply Last reply
              0
              • P Poldi has marked this topic as solved

              • Login

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