summaryrefslogtreecommitdiffstats
path: root/common/resourceaccess.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2016-01-19 11:47:26 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2016-01-19 11:47:26 +0100
commit2cb8a2111eaba3a15bad8cc34bca7c70b51136ef (patch)
tree55eb0b5b98acf98017695fa43cdb4c2c956cf246 /common/resourceaccess.cpp
parent9aa1cf3fb9bb380f6f069fc539b037bfd3d07030 (diff)
downloadsink-2cb8a2111eaba3a15bad8cc34bca7c70b51136ef.tar.gz
sink-2cb8a2111eaba3a15bad8cc34bca7c70b51136ef.zip
Properly deal with delayed invocation in case the object is already gone
Diffstat (limited to 'common/resourceaccess.cpp')
-rw-r--r--common/resourceaccess.cpp11
1 files changed, 5 insertions, 6 deletions
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 @@
46#undef Log 46#undef Log
47#define Log(IDENTIFIER) Akonadi2::Log::debugStream(Akonadi2::Log::DebugLevel::Log, __LINE__, __FILE__, Q_FUNC_INFO, "ResourceAccess("+IDENTIFIER+")") 47#define Log(IDENTIFIER) Akonadi2::Log::debugStream(Akonadi2::Log::DebugLevel::Log, __LINE__, __FILE__, Q_FUNC_INFO, "ResourceAccess("+IDENTIFIER+")")
48 48
49static void queuedInvoke(const std::function<void()> &f) 49static void queuedInvoke(const std::function<void()> &f, QObject *context = 0)
50{ 50{
51 QTimer *timer = new QTimer; 51 auto timer = QSharedPointer<QTimer>::create();
52 QObject::connect(timer, &QTimer::timeout, [=]() { 52 QObject::connect(timer.data(), &QTimer::timeout, context, [f, timer]() {
53 f(); 53 f();
54 delete timer;
55 }); 54 });
56 timer->start(0); 55 timer->start(0);
57} 56}
@@ -536,7 +535,7 @@ bool ResourceAccess::processMessageBuffer()
536 //The callbacks can result in this object getting destroyed directly, so we need to ensure we finish our work first 535 //The callbacks can result in this object getting destroyed directly, so we need to ensure we finish our work first
537 queuedInvoke([=]() { 536 queuedInvoke([=]() {
538 d->callCallbacks(); 537 d->callCallbacks();
539 }); 538 }, this);
540 break; 539 break;
541 } 540 }
542 case Commands::NotificationCommand: { 541 case Commands::NotificationCommand: {
@@ -560,7 +559,7 @@ bool ResourceAccess::processMessageBuffer()
560 //The callbacks can result in this object getting destroyed directly, so we need to ensure we finish our work first 559 //The callbacks can result in this object getting destroyed directly, so we need to ensure we finish our work first
561 queuedInvoke([=]() { 560 queuedInvoke([=]() {
562 emit notification(n); 561 emit notification(n);
563 }); 562 }, this);
564 } 563 }
565 break; 564 break;
566 default: 565 default: