[Interest] How to create QObject-derived class instance from class name

André Somers andre at familiesomers.nl
Tue Mar 1 17:06:49 CET 2016



Op 01/03/2016 om 16:30 schreef Thiago Macieira:
> On terça-feira, 1 de março de 2016 13:59:07 PST André Somers wrote:
>> I think you did not get the point about QMetaType and QMetaObject. They
>> _can_ be used together:
> I don't think that they can.
>
>> 1) mark the constructors in the classes you want to be able to construct
>> from your file as Q_INVOKABLE
>> 2) register the types in the meta object system
> The meta *object* system has no registration.
>
> The meta *type* system requires that the registered type be default-
> constructible and copyable, but QObject is not copyable. Therefore, QObject-
> derived classes cannot be registered with the meta type system.
Am I completely misinterpretting the documentation then?
http://doc.qt.io/qt-5/qmetatype.html#metaObject

If I read that correctly, you can register a 
pointer-to-a-QObject-derived-class-instance and use that. So, indeed, 
you do not register the type, but the type*. And that has no problems 
with being default constructed or copied.

I have not tried this at home, so to speak. Perhaps I should.

André




More information about the Interest mailing list