Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Is it possible to use protobuf/gRPC generated types in QML?
Qt 6.11 is out! See what's new in the release blog

Is it possible to use protobuf/gRPC generated types in QML?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
6 Posts 2 Posters 1.2k 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.
  • J Offline
    J Offline
    jarle
    wrote on last edited by
    #1

    I'm exited about QT's new gRPC support. I'm using it in my current project nextapp, an open source personal manager / productivity app.

    It's works perfectly, and is much simpler to use asynchronously than the native gRPC generated C++ client code. Wrapping it in a trivial C++ template; calling RPC on the server boils down to simply this:

        nextapp::pb::GetNodesReq req;
    
        callRpc<nextapp::pb::NodeTree>([this](nextapp::pb::GetNodesReq req) {
            return client_->GetNodes(req);
        }, [this](const nextapp::pb::NodeTree& tree) {
            emit receivedNodeTree(tree);
        }, req);
    

    Also, the generated types are using native QT types like QString, so they can be used directly in C++ without any type conversion. Very well done!

    Now to my question. I'm using QT 6.6.1. I noticed that there is generated code to use the protobuf generated classes in QML. However, I can not figure out how to get QML to recognize them.

    For example - I may have an object representing a person. I want to pass it to QML to populate a Dialog. Then, when the user press "Save", I want to update the data in the object, and send it back to C++ so that the new data can be sent to the server.

    What am I missing? Note that I'm only trying to use the generated protobuf data types. For now I want C++ to handle all server communication.

    The QT code is here

    semlanikS 1 Reply Last reply
    0
    • J jarle

      I'm exited about QT's new gRPC support. I'm using it in my current project nextapp, an open source personal manager / productivity app.

      It's works perfectly, and is much simpler to use asynchronously than the native gRPC generated C++ client code. Wrapping it in a trivial C++ template; calling RPC on the server boils down to simply this:

          nextapp::pb::GetNodesReq req;
      
          callRpc<nextapp::pb::NodeTree>([this](nextapp::pb::GetNodesReq req) {
              return client_->GetNodes(req);
          }, [this](const nextapp::pb::NodeTree& tree) {
              emit receivedNodeTree(tree);
          }, req);
      

      Also, the generated types are using native QT types like QString, so they can be used directly in C++ without any type conversion. Very well done!

      Now to my question. I'm using QT 6.6.1. I noticed that there is generated code to use the protobuf generated classes in QML. However, I can not figure out how to get QML to recognize them.

      For example - I may have an object representing a person. I want to pass it to QML to populate a Dialog. Then, when the user press "Save", I want to update the data in the object, and send it back to C++ so that the new data can be sent to the server.

      What am I missing? Note that I'm only trying to use the generated protobuf data types. For now I want C++ to handle all server communication.

      The QT code is here

      semlanikS Offline
      semlanikS Offline
      semlanik
      wrote on last edited by
      #2

      @jarle protobuf messages are registered in QML as valuetypes, so the answer to your question 'yes' in general. I will jump into your project this week(probably this evening, who knows) and will give the answer :) The module is in TP we expect that there might be issues for sure :(

      J 1 Reply Last reply
      0
      • semlanikS semlanik

        @jarle protobuf messages are registered in QML as valuetypes, so the answer to your question 'yes' in general. I will jump into your project this week(probably this evening, who knows) and will give the answer :) The module is in TP we expect that there might be issues for sure :(

        J Offline
        J Offline
        jarle
        wrote on last edited by
        #3

        @semlanik Great! I'm looking forward to get this working ;)

        I added a section on the projects readme page about how to run the backend in docker.

        semlanikS 1 Reply Last reply
        0
        • J jarle

          @semlanik Great! I'm looking forward to get this working ;)

          I added a section on the projects readme page about how to run the backend in docker.

          semlanikS Offline
          semlanikS Offline
          semlanik
          wrote on last edited by
          #4

          @jarle I submitted a pull request the the code snippet. Also I will add the documentation topic that describes how to use protobuf types in QML later. And thanks, using your APP I identified couple major issues in current code.

          J 1 Reply Last reply
          0
          • semlanikS semlanik

            @jarle I submitted a pull request the the code snippet. Also I will add the documentation topic that describes how to use protobuf types in QML later. And thanks, using your APP I identified couple major issues in current code.

            J Offline
            J Offline
            jarle
            wrote on last edited by
            #5

            Thanks a lot @semlanik !

            I'm seeing one annoying problem with QT 6.7.0-beta2

            When I compile under Ubuntu, I get this message:

            In file included from /var/local/build/NextAppUi-Desktop_Qt_6_7_0_64-Debug/nextapp_client.grpc.qpb.cpp:3:
            /var/local/build/NextAppUi-Desktop_Qt_6_7_0_64-Debug/nextapp_client.grpc.qpb.h:21:1: error: declaration of anonymous class must be a definition
               21 | class QPB_NEXTAPPGRPCCLIENT_EXPORT Client : public QAbstractGrpcClient
            

            Which seems to boil down do QPB_NEXTAPPGRPCCLIENT_EXPORT not being defined on my system.

            My work-around for now was to just add

            #ifndef QPB_NEXTAPPGRPCCLIENT_EXPORT
            #   define QPB_NEXTAPPGRPCCLIENT_EXPORT
            #endif
            

            to Qt/6.7.0/gcc_64/include/QtGrpc/qabstractgrpcclient.h

            semlanikS 1 Reply Last reply
            0
            • J jarle

              Thanks a lot @semlanik !

              I'm seeing one annoying problem with QT 6.7.0-beta2

              When I compile under Ubuntu, I get this message:

              In file included from /var/local/build/NextAppUi-Desktop_Qt_6_7_0_64-Debug/nextapp_client.grpc.qpb.cpp:3:
              /var/local/build/NextAppUi-Desktop_Qt_6_7_0_64-Debug/nextapp_client.grpc.qpb.h:21:1: error: declaration of anonymous class must be a definition
                 21 | class QPB_NEXTAPPGRPCCLIENT_EXPORT Client : public QAbstractGrpcClient
              

              Which seems to boil down do QPB_NEXTAPPGRPCCLIENT_EXPORT not being defined on my system.

              My work-around for now was to just add

              #ifndef QPB_NEXTAPPGRPCCLIENT_EXPORT
              #   define QPB_NEXTAPPGRPCCLIENT_EXPORT
              #endif
              

              to Qt/6.7.0/gcc_64/include/QtGrpc/qabstractgrpcclient.h

              semlanikS Offline
              semlanikS Offline
              semlanik
              wrote on last edited by
              #6

              @jarle yeah that's something I noticed too, see:
              https://codereview.qt-project.org/c/qt/qtgrpc/+/537001/6
              https://codereview.qt-project.org/c/qt/qtgrpc/+/537004/3

              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