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

Sina Dogru sinadooru at gmail.com
Tue Mar 1 13:40:24 CET 2016


Hello everyone,

Basically, I have a file which I do save some QObject-derived instances
states. I do save them to be able to use those to recover the states of
those QObject-derived instances.

I do also save the QMetaObject::className() in the file. And at the
run-time, I would like to dynamically create QObject-derived instances from
the file.

After a short research on the qt docs, I have ended to use
QMetaType::create() but after tried it, it failed because of this was not
for QObject.. So finally I got the point, QMetaObject is for QObjects and
QMetaType for the others.. But could not find a propert QMetaObject API to
create an instance from string..

Also there is stackoverflow question
<http://stackoverflow.com/questions/7872578/how-to-properly-use-qregistermetatype-on-a-class-derived-from-qobject>
but the answers are not seems like so elegant.

So I have decided to ask your advices how to create QObject-derived class
instance dynamically from a string or class name, even with my that
terrible english, I hope you don't mind it.

Thank you,
Sina
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160301/2be71dc2/attachment.html>


More information about the Interest mailing list