semlanik / qtprotobuf

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

Optional fields not supported #244

Open pontaoski opened 3 years ago

pontaoski commented 3 years ago

Optional fields aren't supported, resulting in this error when you try to use a file with optional fields:

ERROR: profile/v1/stream.proto: is a proto3 file that contains optional fields, but code generator protoc-gen-qtprotobuf hasn't been updated to support optional fields in proto3. Please ask the owner of this code generator to support proto3 optional.--qtprotobuf_out: 
Eijebong commented 2 years ago

Just ran into this, any progress?

semlanik commented 2 years ago

Sorry, all activities are temporary frozen, because of the migration to Qt6. I will try to cover this ASAP. :(

glaubnichtalles commented 1 year ago

Hello,

have also encountered the problem described here and would like to add the following information. From version 3.12 and up to version 3.15 protoc still needs the addition of --experimental_allow_proto3_optional, which is unfortunately not supported with Qt6 using qt_add_protobuf.

Unable to execute /usr/bin/protoc:(1) xxx.proto: This file contains proto3 optional fields, but --experimental_allow_proto3_optional was not set.

A workaround here is to edit the file lib/cmake/Qt6ProtobufTools/Qt6ProtobufToolsMacros.cmake

    string(JOIN "\\$<SEMICOLON>" protoc_arguments
        "--plugin=protoc-gen-${generator}=${generator_file}"
        "--${generator}_out=${tmp_output_directory}"
        "--${generator}_opt=${generation_options_string}"
        "${proto_files_string}"
        "${proto_includes_string}"
        "--experimental_allow_proto3_optional"
    )

Following this, one comes very close to the problem described here, since the error message that now arises is identical.

Unable to execute /usr/bin/protoc:(1) xxx.proto: is a proto3 file that contains optional fields, but code generator protoc-gen-qtprotobufgen hasn't been updated to support optional fields in proto3. Please ask the owner of this code generator to support proto3 optional.

More information about supporting optional can be found in the protobuf repository and I would start by implementing the method uint64_t GetSupportedFeatures() const override in generatorbase.h

King regards

semlanik commented 1 year ago

Hi, @glaubnichtalles the 'optional' fields support is planned for Qt6: QTBUG-103978

Unfortunately I don't plan any backporting from Qt6 to this repo because of complexity.

arietto commented 1 year ago

Hi, I can't open https://bugreports.qt.io/browse/QTBUG-103978 even after login. The problem does exist in Qt 6.5.1 and Qt 6.6.0 (beta).

glaubnichtalles commented 1 year ago

Hi, thanks for the development regarding "Optional fields" support. My latest tests with Qt 6.6.0 beta 3 show that there are problems with the use of reserved c++ keywords. It would be great if for example the following entries could be added to the tests for the proto files:

optional bool private = 13; optional bool public = 42;

Kind reagrds