QMetaType/Doc: update some wording about type registration
Type registration isn't necessary any more, unless you're trying to look up a name back to ID or QMetaType object. It hasn't been since 6.0. Drive-by update the example not to use deprecated API. Drive-by remove the paragraph about requirements that aren't accurate any more. Task-number: QTBUG-104858 Change-Id: Ic6547f8247454b47baa8fffd170eecb66719fa65 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> (cherry picked from commit 5ff637cc140abc07c4c7934fcd6a048a3d0aa66f) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
9af6c08e42
commit
9fd2cb559c
@ -35,12 +35,12 @@ MyStruct s2 = var.value<MyStruct>();
|
|||||||
|
|
||||||
|
|
||||||
//! [3]
|
//! [3]
|
||||||
int id = QMetaType::type("MyClass");
|
QMetaType type = QMetaType::fromName("MyClass");
|
||||||
if (id != QMetaType::UnknownType) {
|
if (type.isValid()) {
|
||||||
void *myClassPtr = QMetaType::create(id);
|
void *myClassPtr = type.create();
|
||||||
...
|
...
|
||||||
QMetaType::destroy(id, myClassPtr);
|
type.destroy(myClassPtr);
|
||||||
myClassPtr = 0;
|
myClassPtr = nullptr;
|
||||||
}
|
}
|
||||||
//! [3]
|
//! [3]
|
||||||
|
|
||||||
|
@ -400,7 +400,8 @@ const char *QtMetaTypePrivate::typedefNameForType(const QtPrivate::QMetaTypeInte
|
|||||||
\omitvalue LastCoreType
|
\omitvalue LastCoreType
|
||||||
\omitvalue LastGuiType
|
\omitvalue LastGuiType
|
||||||
|
|
||||||
Additional types can be registered using Q_DECLARE_METATYPE().
|
Additional types can be registered using qRegisterMetaType() or by calling
|
||||||
|
registerType().
|
||||||
|
|
||||||
\sa type(), typeName()
|
\sa type(), typeName()
|
||||||
*/
|
*/
|
||||||
@ -438,17 +439,19 @@ const char *QtMetaTypePrivate::typedefNameForType(const QtPrivate::QMetaTypeInte
|
|||||||
The class is used as a helper to marshall types in QVariant and
|
The class is used as a helper to marshall types in QVariant and
|
||||||
in queued signals and slots connections. It associates a type
|
in queued signals and slots connections. It associates a type
|
||||||
name to a type so that it can be created and destructed
|
name to a type so that it can be created and destructed
|
||||||
dynamically at run-time. Declare new types with Q_DECLARE_METATYPE()
|
dynamically at run-time.
|
||||||
to make them available to QVariant and other template-based functions.
|
|
||||||
Call qRegisterMetaType() to make types available to non-template based
|
|
||||||
functions, such as the queued signal and slot connections.
|
|
||||||
|
|
||||||
Any class or struct that has a public default
|
Type names can be registered with QMetaType by using either
|
||||||
constructor, a public copy constructor, and a public destructor
|
qRegisterMetaType() or registerType(). Registration is not required for
|
||||||
can be registered.
|
most operations; it's only required for operations that attempt to resolve
|
||||||
|
a type name in string form back to a QMetaType object or the type's ID.
|
||||||
|
Those include some old-style signal-slot connections using
|
||||||
|
QObject::connect(), reading user-types from \l QDataStream to \l QVariant,
|
||||||
|
or binding to other languages and IPC mechanisms, like QML, D-Bus,
|
||||||
|
JavaScript, etc.
|
||||||
|
|
||||||
The following code allocates and destructs an instance of
|
The following code allocates and destructs an instance of \c{MyClass} by
|
||||||
\c{MyClass}:
|
its name, which requires that \c{MyClass} have been previously registered:
|
||||||
|
|
||||||
\snippet code/src_corelib_kernel_qmetatype.cpp 3
|
\snippet code/src_corelib_kernel_qmetatype.cpp 3
|
||||||
|
|
||||||
@ -2673,9 +2676,6 @@ Q_CORE_EXPORT int qMetaTypeTypeInternal(const char *typeName)
|
|||||||
Returns \c true if the object is saved successfully; otherwise
|
Returns \c true if the object is saved successfully; otherwise
|
||||||
returns \c false.
|
returns \c false.
|
||||||
|
|
||||||
The type must have been registered with Q_DECLARE_METATYPE()
|
|
||||||
beforehand.
|
|
||||||
|
|
||||||
Normally, you should not need to call this function directly.
|
Normally, you should not need to call this function directly.
|
||||||
Instead, use QVariant's \c operator<<(), which relies on save()
|
Instead, use QVariant's \c operator<<(), which relies on save()
|
||||||
to stream custom types.
|
to stream custom types.
|
||||||
@ -2714,9 +2714,6 @@ bool QMetaType::save(QDataStream &stream, const void *data) const
|
|||||||
Returns \c true if the object is loaded successfully; otherwise
|
Returns \c true if the object is loaded successfully; otherwise
|
||||||
returns \c false.
|
returns \c false.
|
||||||
|
|
||||||
The type must have been registered with Q_DECLARE_METATYPE()
|
|
||||||
beforehand.
|
|
||||||
|
|
||||||
Normally, you should not need to call this function directly.
|
Normally, you should not need to call this function directly.
|
||||||
Instead, use QVariant's \c operator>>(), which relies on load()
|
Instead, use QVariant's \c operator>>(), which relies on load()
|
||||||
to stream custom types.
|
to stream custom types.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user