[Qt-interest] Comparing two QMetaObjects
Oliver.Knoll at comit.ch
Oliver.Knoll at comit.ch
Mon Feb 7 14:58:59 CET 2011
On 2011-02-07 Gustavo Gustavo de Sá Carvalho Honorato wrote:
> ...
> Suppose I have a object 'a' of a class 'A'. It is guaranteed that
> a->metaObject() will aways return a pointer to A::staticMetaObject?
> Then I can aways compare using:
>
> a->metaObject() != &A::staticMetaObject ?
I am not sure whether a->metaObject will return a pointer to the A::staticMetaObject instance! In fact I doubt it very much, since I think every instance of QObject as its OWN instance of meta object (for the concrete signal/slot connections).
What is it actually you want to achieve again? Do you want to know whether a given instance is of a specific class? Usually that is done with http://doc.qt.nokia.com/4.7/qobject.html#inherits (which makes use of the meta objects), as in:
if (a->inherits(A::staticMetaObject().className()) {...}
(Note: this approach also works if you rename the class A during some refactoring)
Cheers, Oliver
--
Oliver Knoll
Dipl. Informatik-Ing. ETH
COMIT AG - ++41 79 520 95 22
More information about the Qt-interest-old
mailing list