semlanik / qtprotobuf

Protobuf generator and bindings for Qt framework
https://semlanik.github.io/qtprotobuf
MIT License
169 stars 38 forks source link

Nested messages and handling #253

Closed pritamghanghas closed 2 years ago

pritamghanghas commented 2 years ago

Question When we define nested messages, the generated code makes accessor functions for nested messages. These nested messages return const reference type. Which make modifying them quite verbose.

eg.

message Node {
    string name = 1;
    string owner = 2;
}

message AggregateNode {
    string childNode = 1;
    string group = 2;
}

now if we need to assign group from Qt side node.childNode().setGroup("new value") will obviously error out as it childNode() returns a const ref

Only way to modify it I can think of

Node child = node.childNode();
child.group = "new value"
node.setChildNode(child)

I understand that this is to make that variable a QProperty and its changed signal but it is very cumbersome if these objects are used a lot inside the code. Is there a way around it?

Is there a possibility of having something like QList:at and QList::operator[] kind of differentiation to have easy access ot those variables.

Additional context Add any other context or screenshots about the feature request here.

semlanik commented 2 years ago

Well, I think this has historical reasons behind. I already forgot what was the initial implementation, but I think the recent one allows to access non-const members from the return value of message type.

PS: I'm asking to do not use the "Nested Message" term without special needs, since it triggers PTSR relapse :laughing:

pritamghanghas commented 2 years ago

Thanks for the quick fix.