From 2cb8a2111eaba3a15bad8cc34bca7c70b51136ef Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Tue, 19 Jan 2016 11:47:26 +0100 Subject: Properly deal with delayed invocation in case the object is already gone --- common/resourceaccess.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'common/resourceaccess.cpp') diff --git a/common/resourceaccess.cpp b/common/resourceaccess.cpp index c78993b..5c15bbb 100644 --- a/common/resourceaccess.cpp +++ b/common/resourceaccess.cpp @@ -46,12 +46,11 @@ #undef Log #define Log(IDENTIFIER) Akonadi2::Log::debugStream(Akonadi2::Log::DebugLevel::Log, __LINE__, __FILE__, Q_FUNC_INFO, "ResourceAccess("+IDENTIFIER+")") -static void queuedInvoke(const std::function &f) +static void queuedInvoke(const std::function &f, QObject *context = 0) { - QTimer *timer = new QTimer; - QObject::connect(timer, &QTimer::timeout, [=]() { + auto timer = QSharedPointer::create(); + QObject::connect(timer.data(), &QTimer::timeout, context, [f, timer]() { f(); - delete timer; }); timer->start(0); } @@ -536,7 +535,7 @@ bool ResourceAccess::processMessageBuffer() //The callbacks can result in this object getting destroyed directly, so we need to ensure we finish our work first queuedInvoke([=]() { d->callCallbacks(); - }); + }, this); break; } case Commands::NotificationCommand: { @@ -560,7 +559,7 @@ bool ResourceAccess::processMessageBuffer() //The callbacks can result in this object getting destroyed directly, so we need to ensure we finish our work first queuedInvoke([=]() { emit notification(n); - }); + }, this); } break; default: -- cgit v1.2.3