Fix qprotobufmessage_cast() issues


The previous implementation relied on comparing the runtime metaobject
with ToType::staticMetaObject. This is incorrect as message types may
still participate in an inheritance hierarchy and require walking the
parent chain.

The comparison of the message's QProtobufMessage::metaObject()
with ToType::staticMetaObject is only valid if ToType was marked as
final. Otherwise, QMetaObject::inherits() need to be used to walk the
parent chain to find intermediatly-derived classes.

Restrict qprotobufmessage_cast_helper() to QProtobufMessage as the
source type and disallow casting to QProtobufMessage in the public API.

Add tests covering casting behaviour for derived and final custom
message types.

Note: User-derived protobuf messages cannot be detected at runtime
because QProtobufMessage::metaObject() is non-virtual and returns the
parent's metaObject passed during construction. We will modify the
protobuf generator to mark messages as final soon.

Pick-to: 6.11
Change-Id: I57f8b78216e66176d4599620e7bd1bde437911bc
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
commit0f69ad33f93b2c3ae2de588e85caf802e43068d6
parentb8d90c2a43e1879cf0b86f262412bdac5e1f14a6
authorDennis Oberst <dennis.oberst@qt.io>
committerDennis Oberst <dennis.oberst@qt.io>
commit timeThu, 12 Feb 2026 17:13:47 +0100