[Qt-interest] destroyed SLOT

Thiago Macieira thiago at kde.org
Wed Oct 21 13:49:46 CEST 2009


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.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Senior Product Manager - Nokia, Qt Development Frameworks
      PGP/GPG: 0x6EF45358; fingerprint:
      E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20091021/e805d61e/attachment.bin 


More information about the Qt-interest-old mailing list