PDA

View Full Version : What cannot be done in resizeEvent(..)?



nifei
26th December 2008, 02:53
Hi, all,

Detailed Description about my question:
i created a panel widget (subclass of QWidget, (A)) to display some buttons. The count of buttons are dynamically changed in a slot called on_pageCount_changed(int), and this slot is connected with another object's (B) signal called pageCountChanged(int), and this signal is emitted when a resizeEvent happened to both the sender(B) and receiver(A) most of the time.

Summary:
That is to say, a behavior of delete/new children objects of object (A) is triggered by another object, B's signal, and this behavior might be triggered the same time when a resizeEvent happend to (A) or (both A and B).

Some times crash happens (not every time) to
"Unhandled exception at 0x65048e50 (QtGuid4.dll) in demo1120d.exe: 0xC0000005: Access violation reading location 0xfeeefefe."
and if i delete the additional buttons next time the slot is called or if i just hide them, this error will not happen.

so i am wondering if there is any limitation about what could be done when a resizeEvent happened, can objects be delete dynamically or not?

Any help and suggestions will be greatly appreciately, thank you

jpn
26th December 2008, 12:48
You cannot delete the signal sender in a slot because the control returns to the sender after connected slots have been processed. However, you can use QObject::deleteLater() instead.

nifei
29th December 2008, 03:48
You cannot delete the signal sender in a slot because the control returns to the sender after connected slots have been processed. However, you can use QObject::deleteLater() instead.

I donot think it is the deleting of signal sender in a slot that caused the crash, since the dynamically created and deleted buttons are not connected to any signals or slots. However, call QObject::deleteLater()instead indeed solved my problem. I think i misunderstand the order of deleting widgets and resizeEvent and showEvent / paintEvent. call deleteLater is safe here, but i still want to know why the crash happened, why the process call the objects that should have been deleted?

Any way, thank jpn, your advice is really helpful.