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

Sina Dogru sinadooru at gmail.com
Wed Mar 2 11:51:12 CET 2016


>
> > For now there is a design choice which I feel weak myself, to do
> factory or to use QMetaType for creating instances.
>
> Depends on the use case I suppose. If you know the types at compile time,
> as is usually the case I'd go with the simple solution to make a factory. I
> recently, however, had a case where the deserialization routine couldn't
> know at compile time the exact type (i.e. for a library), so I had to put a
> (gadget) base class and use the runtime type ids.
>

Since I'm trying to recover states of the QObject-derived class instances
from a file, it is not possible to know the types at compile time. But is
not that factory was also for creating objects that type is known at
run-time? Or am I missing something? Because I thought both factory and
metaobject system provide run-time object creation?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160302/1b26a1b3/attachment.html>


More information about the Interest mailing list