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

Thiago Macieira thiago.macieira at intel.com
Tue Mar 1 17:21:49 CET 2016


On terça-feira, 1 de março de 2016 17:06:49 PST André Somers wrote:
> > 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.

Correct. You can't register a QObject class with the meta type system, but you 
can register a pointer to a QObject class. The problem is that 
QMetaType::create() will then create a pointer, not the object.

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center




More information about the Interest mailing list