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. QML and protobuf: Issue with repeated nested message

QML and protobuf: Issue with repeated nested message

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 35 Views
  • 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
    Persson
    wrote last edited by
    #1

    Hi,

    I'm having some trouble using a repeated nested message as a property from C++ in QML, for example

    syntax = "proto3";
    
    package messages;
    
    message Foo {
        string name = 1;
    }
    
    message Bar {
        string name = 1;
        Foo foo = 2;
        repeated Foo foos = 3;
        repeated string baz = 4;
    }
    

    being exposed as a property from C++ as

    #ifndef BACKEND_H
    #define BACKEND_H
    
    #include <QObject>
    #include <QQmlEngine>
    
    #include "messages.qpb.h"
    
    class Backend : public QObject
    {
        Q_OBJECT
        QML_ELEMENT
        Q_PROPERTY(messages::Bar bar MEMBER bar_ WRITE setBar NOTIFY barChanged);
    public:
        explicit Backend(QObject *parent = nullptr);
        void setBar(messages::Bar bar);
    signals:
        void barChanged(messages::Bar);
    
    private:
        messages::Bar bar_;
    };
    
    #endif // BACKEND_H
    

    and in QML

    import QtQuick
    import QtQuick.Controls
    
    Window {
        width: 640
        height: 480
        visible: true
        title: qsTr("Hello World")
    
        Label {
            text: {
                print(backend.bar)
                print(backend.bar.foo)
                print(backend.bar.foos)
                print(backend.bar.baz)
                return "Bar name: " + backend.bar.name
            }
        }
    }
    

    This results in "foos" being undefined in QML, the other fields work as expected. Seems like a bug? I created a minimal reproducing example here. I'm using Qt 6.10.2 on Debian 13. Any advice on how to proceed would be appreciated.

    //Daniel

    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