From db3e947e9524a16f63fd5d0d37dbbecfa01a908f Mon Sep 17 00:00:00 2001 From: zhangjiaping Date: Thu, 21 Jan 2021 11:31:53 +0800 Subject: [PATCH] fix(frontend): Optimize code for frontend. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Description: 优化前端Qprocess相关代码 Log: 优化前端Qprocess相关代码 --- src/control/home-page-item.cpp | 11 +++-------- src/control/search-detail-view.cpp | 18 +++++------------- 2 files changed, 8 insertions(+), 21 deletions(-) diff --git a/src/control/home-page-item.cpp b/src/control/home-page-item.cpp index 0e92bc1..9d24974 100644 --- a/src/control/home-page-item.cpp +++ b/src/control/home-page-item.cpp @@ -35,19 +35,14 @@ void HomePageItem::setupUi(const int& type, const QString& path) { case SearchListView::ResType::Dir: case SearchListView::ResType::File: { QProcess process; - process.start(QString("xdg-open %1").arg(path)); + process.startDetached(QString("xdg-open %1").arg(path)); process.waitForFinished(); break; } case SearchListView::ResType::Setting: { //打开控制面板对应页面 - QProcess * process = new QProcess; - connect(process, static_cast(&QProcess::finished), this, [ = ]() { - if (process) { - delete process; - } - }); - process->start(QString("ukui-control-center --%1").arg(path.left(path.indexOf("/")).toLower())); + QProcess process; + process.startDetached(QString("ukui-control-center --%1").arg(path.left(path.indexOf("/")).toLower())); break; } default: diff --git a/src/control/search-detail-view.cpp b/src/control/search-detail-view.cpp index a427d2f..76b102e 100644 --- a/src/control/search-detail-view.cpp +++ b/src/control/search-detail-view.cpp @@ -253,20 +253,14 @@ bool SearchDetailView::openAction(const int& type, const QString& path) { case SearchListView::ResType::Dir: case SearchListView::ResType::File: { QProcess process; - process.start(QString("xdg-open %1").arg(path)); - process.waitForFinished(); + process.startDetached(QString("xdg-open %1").arg(path)); return true; break; } case SearchListView::ResType::Setting: { //打开控制面板对应页面 - QProcess * process = new QProcess; - connect(process, static_cast(&QProcess::finished), this, [ = ]() { - if (process) { - delete process; - } - }); - process->start(QString("ukui-control-center --%1").arg(path.left(path.indexOf("/")).toLower())); + QProcess process; + process.startDetached(QString("ukui-control-center --%1").arg(path.left(path.indexOf("/")).toLower())); return true; break; } @@ -391,8 +385,7 @@ bool SearchDetailView::addDesktopShortcut(const QString& path) { if(ret) { QProcess process; - process.start(QString("chmod a+x %1").arg(newName)); - process.waitForFinished(); + process.startDetached(QString("chmod a+x %1").arg(newName)); return true; } return false; @@ -426,8 +419,7 @@ bool SearchDetailView::addPanelShortcut(const QString& path) { */ bool SearchDetailView::openPathAction(const QString& path) { QProcess process; - process.start(QString("xdg-open %1").arg(path.left(path.lastIndexOf("/")))); - process.waitForFinished(); + process.startDetached(QString("xdg-open %1").arg(path.left(path.lastIndexOf("/")))); return true; }