[Interest] QMetaType::metaObjectForType
Stephen Kelly
stephen.kelly at kdab.com
Mon Feb 17 11:05:45 CET 2014
On Monday, February 17, 2014 09:47:20 you wrote:
> Hi
> Thanks for your quick reply.
> This does indeed work, but I would be grateful if you could explain why
>
> > Q_DECLARE_METATYPE(Widget)
>
> Remove this line.
You don't pass around copies of QObject derived types because it is not
copyable. You pass around pointers instead. So, you don't want 'Widget' to be
a metatype, you want 'Widget*' to be a metatype so that you can put a Widget*
in a QVariant for example.
You can use
Q_DECLARE_METATYPE(Widget*)
but it is not needed as of Qt 5.0. There's some background info here:
http://steveire.wordpress.com/2011/03/16/implementing-qvariantqmetatype-features-with-template-tricks/
and the problems were solved and implemented in 5.0
http://www.kdab.com/kdab-contributions-to-qt-5-0-part-1/
So, it's better to remove the Q_DECLARE_METATYPE that you don't need rather
than add one that is wrong.
> > Class.cpp
> > const int WidgetTypeID = qRegisterMetaType<Widget>("Widget");
>
> Register the pointer. Don't specify the string:
>
> qRegisterMetaType<Widget*>();
By using a string there, you run the risk of typos. The string is not needed
and should not be used (even with Qt 4 code).
Thanks,
--
Stephen Kelly <stephen.kelly at kdab.com> | Software Engineer
KDAB (Deutschland) GmbH & Co.KG, a KDAB Group Company
www.kdab.com || Germany +49-30-521325470 || Sweden (HQ) +46-563-540090
KDAB - Qt Experts - Platform-Independent Software Solutions
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20140217/a1639dd3/attachment.sig>
More information about the Interest
mailing list