[Interest] metaObject from class name

Keith Gardner kreios4004 at gmail.com
Fri Feb 14 16:21:20 CET 2014


If you register the class with QMetaType with Q_DECLARE_METATYPE(Class*),
you can then call QMetaType::type("Class").  With the returned int, you can
then call QMetaType::metaObjectForType(integer).  I think this is what you
are looking for.

class Foo : public QObject
{
    ...
};
Q_DECLARE_METATYPE(Foo*)

const char *string = "Foo";
const QMetaObject* metaObject =
QMetaType::metaObjectForType(QMetaType::type(string));

I haven't tried compiling this but I believe this is how it will work based
off of the docs for QMetaType.

Keith



On Fri, Feb 14, 2014 at 9:14 AM, Jason H <scorp1us at yahoo.com> wrote:

> I'm not 10% udnerstanding your intentions, but this might help. You can
> create any QObject through QMetaObject by the class name, then get the meta
> object for the created object. Look at QMetaObject::newInstance(..)
>
> You need a "class factory" design pattern.
>
> Here is an example:
>
> http://www.ics.com/designpatterns/solutions/abstractfactory.html#abstractfactoryh
>
>
>   ------------------------------
>  *From:* Graham Labdon <Graham.Labdon at avalonsciences.com>
> *To:* "interest at qt-project.org" <interest at qt-project.org>
> *Sent:* Friday, February 14, 2014 5:50 AM
> *Subject:* [Interest] metaObject from class name
>
>
> Hi
> In my application I have a class name as a string
> This is the name of a class derived from QObject.
> Now what I would like to do is the get metaObject for this class from the
> string
>
> Is this at all possible?
>
> Many thanks
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
>
>
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20140214/f0dfa5f9/attachment.html>


More information about the Interest mailing list