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();