[Interest] qobject_cast

Igor Mironchik igor.mironchik at gmail.com
Thu Apr 20 09:04:32 CEST 2017


Hi,

> If sender() is a Channel*, then qobject_cast should not fail.
>
> Try to add this to your slot, this will print the inheritance list
>
>      qDebug() << "Looking for" << &Channel::staticMetaObject <<
> Channel::staticMetaObject.className() << "on" << sender() <<
> qobject_cast< Channel* > ( sender() )
>      const QMetaObject *mo = sender->metaObject();
>     while (mo != nullptr) {
>          qDebug() << mo << mo->className() << (mo ==
> &Channel::staticMetaObject ? "<-" : "");
>          mo = mo->superClass();
>      }
>
> This is roughly how QMetaObject::inherits() works. if you get the
> "<-", then qobject_cast should work as expected.

I got:

Looking for 0xe6b188 Globe::Channel on Globe::ComoChannel(0x4500270, 
name = "Channel") QObject(0x0)

0xd49548 Globe::ComoChannel

0xd4f060 Globe::Channel

0x6683c44c QObject


And as I can guess it's because of static linking. I.e. I have static 
lib where Channel defined. And this lib linking to app and to plugin.


Am I right that I should use dynamic libs?


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20170420/f2a5b6fc/attachment.html>


More information about the Interest mailing list