Do not call QueuedConnection slot on partialy destroyed object
This is a regression introduced in Qt 4.8 When QApplication::processEvents is called from a destructor, it is possible that pending events would still be called on the already destroyed subclass. Prevent that by using the same pattern as in QMetaObject::activate Change-Id: Ida50db07ae089264402dafcde7a41a066479d08b Reviewed-by: Bradley T. Hughes <bradley.hughes@nokia.com> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@nokia.com>
This commit is contained in:
parent
bbc098ab9f
commit
87679491cb
@ -429,7 +429,7 @@ void QMetaCallEvent::placeMetaCall(QObject *object)
|
||||
{
|
||||
if (slotObj_) {
|
||||
slotObj_->call(object, args_);
|
||||
} else if (callFunction_) {
|
||||
} else if (callFunction_ && method_offset_ <= object->metaObject()->methodOffset()) {
|
||||
callFunction_(object, QMetaObject::InvokeMetaMethod, method_relative_, args_);
|
||||
} else {
|
||||
QMetaObject::metacall(object, QMetaObject::InvokeMetaMethod, method_offset_ + method_relative_, args_);
|
||||
|
@ -4101,12 +4101,25 @@ public slots:
|
||||
}
|
||||
};
|
||||
|
||||
static void processEvents()
|
||||
{
|
||||
qApp->processEvents();
|
||||
}
|
||||
|
||||
void tst_QObject::baseDestroyed()
|
||||
{
|
||||
BaseDestroyed d;
|
||||
connect(&d, SIGNAL(destroyed()), &d, SLOT(slotUseList()));
|
||||
//When d goes out of scope, slotUseList should not be called as the BaseDestroyed has
|
||||
// already been destroyed while ~QObject emit destroyed
|
||||
{
|
||||
BaseDestroyed d;
|
||||
connect(&d, SIGNAL(destroyed()), &d, SLOT(slotUseList()));
|
||||
//When d goes out of scope, slotUseList should not be called as the BaseDestroyed has
|
||||
// already been destroyed while ~QObject emit destroyed
|
||||
}
|
||||
{
|
||||
BaseDestroyed d;
|
||||
connect(&d, &QObject::destroyed, processEvents);
|
||||
QMetaObject::invokeMethod(&d, "slotUseList", Qt::QueuedConnection);
|
||||
//the destructor will call processEvents, that should not call the slotUseList
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QObject::pointerConnect()
|
||||
|
Loading…
Reference in New Issue
Block a user