[Interest] Qt 4.8, MetaType

Alexander Syvak alexander.svk at gmail.com
Fri Jul 26 09:22:07 CEST 2013


Good day!

In the book C++ GUI Programming with Qt 4 (2nd Edition) there's not much
information about QMetaType and the Qt's internal subsystem.
There's the statement at
qRegisterMetaType<http://qt-project.org/doc/qt-5.0/qtcore/qmetatype.html#qRegisterMetaType>
which
says "...After a type has been registered, you can create and destroy
objects of that type dynamically at run-time.
To use the type T in
QVariant<http://qt-project.org/doc/qt-5.0/qtcore/qvariant.html>,
using Q_DECLARE_METATYPE<http://qt-project.org/doc/qt-5.0/qtcore/qmetatype.html#Q_DECLARE_METATYPE>()
is sufficient. To use the type T in queued signal and slot connections,
qRegisterMetaType<T>() must be called before the first connection is
established...." .
After reading qmetatype.cpp and qmetatype.h everything Q_DECLARE_METATYPE
does is specialization of QMetaTypeId template structure.
QVariant inside the static function compare in qvariant.cpp uses
QMetaType::IsRegistered method which in fact checks if the type was
registered in customTypes using either qRegisterMetaType or
QMetaTypeId<T>::qt_metatype_id() after Q_DECLARE_METATYPE.
Why is it sufficient then to use Q_DECLARE_METATYPE for any template using
the declared type?
qRegisterMetaType only puts the type to be registered into customTypes
vector registering constructor and destructor for the type with an ID
(optionally an user may register operator>> and operator<< for the type).
Why is it needed to use queued signal and slot connections and
QObject::property() API?
Furthermore, Q_OBJECT is required for a type using slots/signals. QObject
does not meet CopyConstructible requirement for using either
Q_DECLARE_METATYPE or qRegisterMetaType.

I'd like to ask you to clearify this.

Thank you.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20130726/5ded4d0b/attachment.html>


More information about the Interest mailing list