[Interest] QMetaType::metaObjectForType

Graham Labdon Graham.Labdon at avalonsciences.com
Mon Feb 17 10:47:20 CET 2014


Hi
Thanks for your quick reply.
This does indeed work, but I would be grateful if you could explain why

Thanks

-----Original Message-----
From: interest-bounces+graham.labdon=avalonsciences.com at qt-project.org [mailto:interest-bounces+graham.labdon=avalonsciences.com at qt-project.org] On Behalf Of Stephen Kelly
Sent: 17 February 2014 09:41
To: interest at qt-project.org
Subject: Re: [Interest] QMetaType::metaObjectForType

On Monday, February 17, 2014 09:37:00 Graham Labdon wrote:
> Hi
> 
> I am trying to use QMetaType::metaObjectForType but it is always 
> returning NULL
> 
> I have attached my class declaration and would be grateful if anyone 
> can explain why I am getting a NULL return value
> 
> Many thanks
> metatype.txt
> metatype.txt
> Class.h -
> class Widget : public QWidget
> {
>     Q_OBJECT
> 
> public:
>     Q_INVOKABLE Widget(QWidget *parent=0);
>     Widget(const Widget& other);
>     ~Widget();
> };
> 
> Q_DECLARE_METATYPE(Widget)

Remove this line.

> 
> Class.cpp
> const int WidgetTypeID = qRegisterMetaType<Widget>("Widget");

Register the pointer. Don't specify the string:

 qRegisterMetaType<Widget*>();

Most likely you should move this from global scope to your usage section.


> 
> Usage
>         int id = QMetaType::type("Widget");

int id = QMetaType::type("Widget*");

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



More information about the Interest mailing list