1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-21 00:09:47 +01:00

Only invoke Closure if receiver still exists

This commit is contained in:
Uwe L. Korn 2013-06-14 12:23:04 +02:00
parent f3b028d020
commit e976774d52
2 changed files with 26 additions and 14 deletions

View File

@ -80,20 +80,31 @@ void Closure::Connect(QObject* sender, const char* signal) {
Q_UNUSED(success);
}
void Closure::Invoked() {
if (callback_) {
callback_();
} else {
slot_.invoke(
parent() ? parent() : outOfThreadReceiver_,
val0_ ? val0_->arg() : QGenericArgument(),
val1_ ? val1_->arg() : QGenericArgument(),
val2_ ? val2_->arg() : QGenericArgument(),
val3_ ? val3_->arg() : QGenericArgument());
}
void
Closure::Invoked() {
if ( callback_ )
{
callback_();
}
else
{
// Only invoke the closure if the receiver still exists
// Hint: If parent was destroyed, this closure would also be destroyed
if ( parent() || !outOfThreadReceiver_.isNull() )
{
slot_.invoke(
parent() ? parent() : outOfThreadReceiver_.data(),
val0_ ? val0_->arg() : QGenericArgument(),
val1_ ? val1_->arg() : QGenericArgument(),
val2_ ? val2_->arg() : QGenericArgument(),
val3_ ? val3_->arg() : QGenericArgument());
}
}
if ( autoDelete_ )
deleteLater();
if ( autoDelete_ )
{
deleteLater();
}
}
void Closure::Cleanup() {

View File

@ -31,6 +31,7 @@ using std::tr1::function;
#include <QMetaMethod>
#include <QObject>
#include <QPointer>
#include <QSharedPointer>
#include <boost/noncopyable.hpp>
@ -95,7 +96,7 @@ class DLLEXPORT Closure : public QObject, boost::noncopyable {
QMetaMethod slot_;
function<void()> callback_;
bool autoDelete_;
QObject* outOfThreadReceiver_;
QPointer<QObject> outOfThreadReceiver_;
boost::scoped_ptr<const ClosureArgumentWrapper> val0_;
boost::scoped_ptr<const ClosureArgumentWrapper> val1_;