qtprotobufgen: Generate QtProtobuf messages as 'final' in 6.11
Teach the QtProtobuf generator to add the 'final' specifier to generated
message classes. Message classes are now generated as 'final' by
default.
This is true for user accessed QtProtobuf generation, but the provided
QtCoreTypes, QtGuiTypes and WellKnownTypes will still be generated as
non final until the next LTS release.
Subclassing generated QtProtobuf messages is not a supported use case.
QProtobufMessage does not provide the necessary facilities for safe
inheritance, and extending generated message types is also questionable
from a design and logic perspective. Generating non-final classes
therefore encouraged a pattern that does not work reliably in practice.
To preserve backwards compatibility, introduce the
'GENERATE_NON_FINAL_MESSAGES' CMake / command-line option, which
restores the previous non-final generation behavior when explicitly
requested.
Add test coverage for the new option and update the existing
generated-class comparison tests accordingly.
Found during the Qt 6.11 API review.
[ChangeLog][Important Behavior Changes] Generated QtProtobuf message
classes are now final by default. A new GENERATE_NON_FINAL_MESSAGES
option was added to restore the previous behavior for backwards
compatibility.
Pick-to: 6.11
Change-Id: I315845e6f090b5ac34681b2dfcae8ee876b28256
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
| commit | 25a55b553ebc26e76152d6478888c050452dad7e |
| parent | c7e57d1badf31cdeb459581d19ca39015dae673c |
| author | Dennis Oberst <dennis.oberst@qt.io> |
| committer | Dennis Oberst <dennis.oberst@qt.io> |
| commit time | Thu, 12 Feb 2026 17:13:59 +0100 |
- M src/protobuf/Qt6ProtobufBuildInternals.cmake
- M src/protobuf/doc/src/qt-add-protobuf.qdoc
- M src/protobuf/doc/src/qtprotobufgen.qdoc
- M src/tools/doc/qtprotoccommon.qdocinc
- M src/tools/qtprotobufgen/Qt6ProtobufToolsMacros.cmake
- M src/tools/qtprotobufgen/messagedeclarationprinter.cpp
- M src/tools/qtprotoccommon/commontemplates.cpp
- M src/tools/qtprotoccommon/commontemplates.h
- M src/tools/qtprotoccommon/options.cpp
- M src/tools/qtprotoccommon/options.h
- M src/wellknown/Qt6ProtobufWellKnownTypesBuildInternals.cmake
- M tests/auto/grpcgen/data/cmake_generated/invalid-identifier/666-invalid-identifier.qpb.h
- M tests/auto/grpcgen/data/cmake_generated/protobuf_common/qtgrpc/tests/qtgrpcgen.qpb.h
- M tests/auto/grpcgen/data/cmake_generated/qml/qtgrpcgen.qpb.h
- M tests/auto/protobuf/basic/CMakeLists.txt
- M tests/auto/protobuf/basic/tst_protobuf_internals.cpp
- M tests/auto/protobufgen/CMakeLists.txt
- M tests/auto/protobufgen/data/cmake_generated/copy_comments/annotation.qpb.h
- M tests/auto/protobufgen/data/cmake_generated/export_macro/qtprotobufgen.qpb.h
- M tests/auto/protobufgen/data/cmake_generated/extra_namespace/qtprotobufgen.qpb.h
- M tests/auto/protobufgen/data/cmake_generated/generate_package_subfolders/qt/protobuf/qtprotobufgen.qpb.h
- M tests/auto/protobufgen/data/cmake_generated/no_options/qtprotobufgen.qpb.h
- A tests/auto/protobufgen/data/cmake_generated/non_final_messages/qtprotobufgenminimal.qpb.cpp
- A tests/auto/protobufgen/data/cmake_generated/non_final_messages/qtprotobufgenminimal.qpb.h
- A tests/auto/protobufgen/data/cmake_generated/non_final_messages/qtprotobufgenminimal_qtprotoreg.cpp
- M tests/auto/protobufgen/data/cmake_generated/qml/qtprotobufgen.qpb.h
- M tests/auto/protobufgen/data/cmake_generated/qml_uri/qtprotobufgen.qpb.h
- M tests/auto/protobufgen/data/cmake_generated/static/qtprotobufgen.qpb.h
- M tests/auto/protobufgen/data/cmd_line_generated/copy_comments/annotation.qpb.h
- M tests/auto/protobufgen/data/cmd_line_generated/export_macro/qtprotobufgen.qpb.h
- M tests/auto/protobufgen/data/cmd_line_generated/export_macro_custom_file_name/qtprotobufgen.qpb.h
- M tests/auto/protobufgen/data/cmd_line_generated/export_macro_custom_file_name_force_generate/qtprotobufgen.qpb.h
- M tests/auto/protobufgen/data/cmd_line_generated/export_macro_custom_file_name_skip_generate/qtprotobufgen.qpb.h
- M tests/auto/protobufgen/data/cmd_line_generated/extra_namespace/qtprotobufgen.qpb.h
- M tests/auto/protobufgen/data/cmd_line_generated/generate_package_subfolders/qt/protobuf/qtprotobufgen.qpb.h
- M tests/auto/protobufgen/data/cmd_line_generated/header_guard_filename/qtprotobufgenminimal.qpb.h
- M tests/auto/protobufgen/data/cmd_line_generated/header_guard_pragma/qtprotobufgenminimal.qpb.h
- M tests/auto/protobufgen/data/cmd_line_generated/no_options/qtprotobufgen.qpb.h
- A tests/auto/protobufgen/data/cmd_line_generated/non_final_messages/qtprotobufgenminimal.qpb.cpp
- A tests/auto/protobufgen/data/cmd_line_generated/non_final_messages/qtprotobufgenminimal.qpb.h
- A tests/auto/protobufgen/data/cmd_line_generated/non_final_messages/qtprotobufgenminimal_qtprotoreg.cpp
- M tests/auto/protobufgen/data/cmd_line_generated/qml/qtprotobufgen.qpb.h
- M tests/auto/protobufgen/data/cmd_line_generated/qml_uri/qtprotobufgen.qpb.h
- M tests/auto/protobufgen/data/cmd_line_generated/qml_uri_export_macro/qtprotobufgen.qpb.h
- M tests/auto/protobufgen/data/cmd_line_generated/qml_uri_export_macro_generate_package_subfolders/qt/protobuf/qtprotobufgen.qpb.h
- M tests/auto/protobufgen/tst_qtprotobufgen.cpp