diff options
| author | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2025-09-12 23:38:00 +1000 |
|---|---|---|
| committer | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2025-09-12 23:38:00 +1000 |
| commit | 5687a216cad4b17f0321ae062ac6965a4f54120f (patch) | |
| tree | ece5a5c45b31399c0c347fa380dcc8d58fc7f9bd /plugin | |
| parent | internal: fix crash (diff) | |
| download | caelestia-shell-5687a216cad4b17f0321ae062ac6965a4f54120f.tar.gz caelestia-shell-5687a216cad4b17f0321ae062ac6965a4f54120f.tar.bz2 caelestia-shell-5687a216cad4b17f0321ae062ac6965a4f54120f.zip | |
plugin/service: fix invoke after destruction
Diffstat (limited to 'plugin')
| -rw-r--r-- | plugin/src/Caelestia/service.cpp | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/plugin/src/Caelestia/service.cpp b/plugin/src/Caelestia/service.cpp index 941138f..bc919c9 100644 --- a/plugin/src/Caelestia/service.cpp +++ b/plugin/src/Caelestia/service.cpp @@ -1,6 +1,7 @@ #include "service.hpp" #include <qdebug.h> +#include <qpointer.h> namespace caelestia { @@ -26,7 +27,15 @@ void Service::ref() { emit refCountChanged(); if (needsStart) { - QMetaObject::invokeMethod(this, &Service::start, Qt::QueuedConnection); + const QPointer<Service> self(this); + QMetaObject::invokeMethod( + this, + [self]() { + if (self) { + self->start(); + } + }, + Qt::QueuedConnection); } } @@ -46,7 +55,15 @@ void Service::unref() { emit refCountChanged(); if (needsStop) { - QMetaObject::invokeMethod(this, &Service::stop, Qt::QueuedConnection); + const QPointer<Service> self(this); + QMetaObject::invokeMethod( + this, + [self]() { + if (self) { + self->stop(); + } + }, + Qt::QueuedConnection); } } |