From edd051de40810bb4f062d9161b7efed90af7e44c Mon Sep 17 00:00:00 2001 From: iaom Date: Fri, 15 Sep 2023 09:23:23 +0800 Subject: [PATCH] =?UTF-8?q?fix(frontend):=E4=BF=AE=E5=A4=8D=E4=BA=86?= =?UTF-8?q?=E4=B8=80=E4=B8=AA=E8=BF=9C=E7=A8=8B=E6=A1=8C=E9=9D=A2=E8=BF=9E?= =?UTF-8?q?=E6=8E=A5=E6=97=B6=E5=81=B6=E7=8E=B0=E7=9A=84=E5=B4=A9=E6=BA=83?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 该问题曾导致远程连接建立后,本地进程退出后,远程的进程dbus接口被调用时偶现崩溃 --- frontend/ukui-search-dbus-service.cpp | 21 +++------------------ frontend/ukui-search-dbus-service.h | 1 - 2 files changed, 3 insertions(+), 19 deletions(-) diff --git a/frontend/ukui-search-dbus-service.cpp b/frontend/ukui-search-dbus-service.cpp index f6a4ddc..f18958c 100644 --- a/frontend/ukui-search-dbus-service.cpp +++ b/frontend/ukui-search-dbus-service.cpp @@ -73,21 +73,9 @@ UkuiSearchDbusServices::UkuiSearchDbusServices(MainWindow *m, QObject *parent): } } -UkuiSearchDbusServices::~UkuiSearchDbusServices() -{ - if(m_watcher) { - delete m_watcher; - m_watcher = nullptr; - } - if(m_serviceIface) { - delete m_serviceIface; - m_serviceIface = nullptr; - } -} - void UkuiSearchDbusServices::initWatcher() { - m_watcher = new QDBusServiceWatcher(QStringLiteral("com.ukui.search.service"),QDBusConnection::sessionBus(), QDBusServiceWatcher::WatchForOwnerChange); + m_watcher = new QDBusServiceWatcher(QStringLiteral("com.ukui.search.service"),QDBusConnection::sessionBus(), QDBusServiceWatcher::WatchForOwnerChange, this); connect(m_watcher, &QDBusServiceWatcher::serviceOwnerChanged, this, &UkuiSearchDbusServices::onServiceOwnerChanged); connectToService(); } @@ -131,9 +119,7 @@ UkuiSearchDbusServices::onServiceOwnerChanged(const QString &service, const QStr void UkuiSearchDbusServices::connectToService() { - if(!m_serviceIface) { - m_serviceIface = new OrgUkuiSearchServiceInterface(QStringLiteral("com.ukui.search.service"), "/", QDBusConnection::sessionBus()); - } + m_serviceIface = new OrgUkuiSearchServiceInterface(QStringLiteral("com.ukui.search.service"), "/", QDBusConnection::sessionBus(), this); connect(m_serviceIface, &OrgUkuiSearchServiceInterface::showWindowSignal, this, &UkuiSearchDbusServices::onShowWindow); connect(m_serviceIface, &OrgUkuiSearchServiceInterface::searchKeywordSignal, this, &UkuiSearchDbusServices::onSearchKeyword); connect(m_serviceIface, &OrgUkuiSearchServiceInterface::mainWindowSwitchSignal, this, &UkuiSearchDbusServices::onMainWindowSwitch); @@ -143,8 +129,7 @@ void UkuiSearchDbusServices::disConnectToService() { if(m_serviceIface) { m_serviceIface->disconnect(); - delete m_serviceIface; - m_serviceIface = nullptr; + m_serviceIface->deleteLater(); } } diff --git a/frontend/ukui-search-dbus-service.h b/frontend/ukui-search-dbus-service.h index 329c4a6..35f2dff 100644 --- a/frontend/ukui-search-dbus-service.h +++ b/frontend/ukui-search-dbus-service.h @@ -37,7 +37,6 @@ class UkuiSearchDbusServices: public QObject, public QDBusContext public: explicit UkuiSearchDbusServices(MainWindow *m, QObject *parent = nullptr); - ~UkuiSearchDbusServices(); public Q_SLOTS: void showWindow();