[Qt-interest] destroyed SLOT

Andre Somers andre at familiesomers.nl
Wed Oct 21 14:53:15 CEST 2009


Thiago Macieira wrote:
> Em Quarta-feira 21 Outubro 2009, às 09:17:44, você escreveu:
>   
>> Is there *ever* a reason why handleClose() would not be called here:
>>
>> settingsWidget_ = new QWidget;
>> QObject::connect( settingsWidget_, SIGNAL(destroyed()), this,
>> SLOT(handleClose()));
>> delete settingsWidget_;
>>
>> A lot of my objects have settingsWidgets_'s and in all cases but one
>> handleClose() gets called when they get deleted.  I'm at a bit of a
>> loss.  How should I go about debugging this?  I've tried
>> dumpObjectInfo() but it doesn't print anything (even in debug) and the
>> connect call returns true.  Any thoughts would be great.  I'm on hour
>> 10 of  this problem :)
>>     
>
> Yes, the reason is the C++ language.
>
> The destroyed(QObject*) signal is emitted from the QObject and QWidget 
> destructors. That means that, when they are emitted, your object *is* a 
> QObject or a QWidget. It no longer has a method called "handleClose".
>
> Therefore, handleClose cannot be called.
>
> You must never connect the destroyed(QObject*) signal to "this". You have to 
> connect it to another object.
>
>   
As I read the code, the connection is made from another object than the 
one that is being destroyed. The object pointer for the signal is not 
this, but settingsWidget_. That would invalidate your explanation in 
this case, would it not? Unless of course settingsWidget_ is a child 
widget of this.

André




More information about the Qt-interest-old mailing list