[Interest] qobject_cast

Igor Mironchik igor.mironchik at gmail.com
Thu Apr 20 17:47:46 CEST 2017


Hi,


20.04.2017 18:22, Thiago Macieira пишет:
> Em quarta-feira, 19 de abril de 2017, às 22:56:46 PDT, Igor Mironchik
> escreveu:
>> class Channel
>>
>>     :  public QObject
>>
>> {};
>> void mySlot()
>> {
>>     Channel * ch = qobject_cast< Channel* > ( sender() );
>>     // You are 100% sure that sender() is Channel!!!
>>     // And this cast will fail!!!
>> }
> And so will dynamic_cast fail.
>
> Fix it by adding a non-inline virtual destructor to Channel.

Sure. It's just a pseudo code.

In real code was virtual destructor and dynamic_cast and static_cast 
worked, but qobject_cast failed.

The reason was in static linking of Channel to the application and to 
the plugin.



More information about the Interest mailing list