[Development] Q_Q(), static_cast or reinterpret_cast?

Alberto Mardegan mardy at users.sourceforge.net
Fri Jun 29 12:31:06 CEST 2012


On 06/29/2012 02:17 PM, Thiago Macieira wrote:
> On sexta-feira, 29 de junho de 2012 13.14.41, Alberto Mardegan wrote:
>> Hi all,
>>     I just run into an issue in Qt 4.8 QDeclarativeItem (but please read
>> on, the topic regards qt5 too): the geometryChanged() virtual method is
>> not invoked when the size of the item is changed by modifying the
>> "width" or "height" properties (for instance, from QML).
>> The QDeclarativeItem's geometryChanged() method, however, is called (I
>> can tell it because it's the only place where the widthChanged() signal
>> is emitted, and I verified that the signal is indeed emitted).
>
> You said that QDeclarativeItem geometryChanged() isn't called, but
> QDeclarativeITem's geometryChanged() is called. :-)

Sorry, I meant to say that the method in the derived class is not 
called, but the one in the base class (QDeclarativeItem) is.

> That can't be. The q pointer is of type QDeclarativeItem* and
> geometryChanged() is a new virtual protected method there. It will do a
> virtual invocation in any case. Disassembly confirms it:

Indeed. And the pointer returned by static_cast() or reinterpret_cast() 
would be the anyway same -- I was just suspecting that GCC could be 
making some wrong assumptions/optimizations when static_cast() is used.
But recompiling the project with debugging enabled made everything work, 
which points at some weird mistake on my side.
The thing that set me on the wrong way is that my virtual method in the 
derived class _was called_ when invoked from methods in 
QDeclarativeItem, but not from methods in QDeclarativeItemPrivate.

Nevermind, anyway. :-)

Ciao,
   Alberto



More information about the Development mailing list