QProtobufMessage Class
Base class for all protobuf messages. More...
| Header: | #include <QProtobufMessage> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS Protobuf)target_link_libraries(mytarget PRIVATE Qt6::Protobuf) |
| Since: | Qt 6.5 |
| Inherited By: |
Related Non-Members
(since 6.11) To | qprotobufmessage_cast(QProtobufMessage *from) |
(since 6.11) To | qprotobufmessage_cast(const QProtobufMessage *from) |
Detailed Description
Provides access to the properties of a message, using setProperty() and property(), without depending on what the message is.
Related Non-Members
[since 6.11] template <typename To> To qprotobufmessage_cast(QProtobufMessage *from)
[since 6.11] template <typename To> To qprotobufmessage_cast(const QProtobufMessage *from)
Returns the given from object cast to pointer type To if the object is of type To (or a subclass); otherwise returns nullptr. If from is nullptr, this function also returns nullptr.
The template argument To must be a pointer to a class that inherits from QProtobufMessage and is declared with the Q_PROTOBUF_OBJECT macro.
Example:
QProtobufMessage *message = new myproject::MySpecificMessage(); // Cast to its own type (success) auto *specific = qprotobufmessage_cast<myproject::MySpecificMessage *>(message); // specific is a valid pointer // Cast to an unrelated type (failure) auto *another = qprotobufmessage_cast<myproject::AnotherMessage *>(message); // another is nullptr
This function behaves similarly to the standard C++ dynamic_cast(), with the advantages that it doesn't require RTTI support and works across dynamic library boundaries.
Warning: If the type pointed to by To is not declared with the Q_PROTOBUF_OBJECT macro, this function's return value is undefined.
These functions were introduced in Qt 6.11.