From 145ae607b578ae6246fa41524ef55a841265f64f Mon Sep 17 00:00:00 2001 From: cutefishd Date: Mon, 19 Apr 2021 04:44:03 +0800 Subject: [PATCH] Fixed that sidebar was not selected after the disk was mounted --- model/placesitem.cpp | 8 ++++---- model/placesmodel.cpp | 8 ++++++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/model/placesitem.cpp b/model/placesitem.cpp index 2e2476c..ba87969 100644 --- a/model/placesitem.cpp +++ b/model/placesitem.cpp @@ -62,9 +62,6 @@ void PlacesItem::setIconPath(const QString &path) QUrl PlacesItem::url() const { - if (m_access) - return QUrl::fromLocalFile(m_access->filePath()); - return m_url; } @@ -75,7 +72,10 @@ void PlacesItem::setUrl(const QUrl &url) QString PlacesItem::path() const { - return m_url.toString(QUrl::PreferLocalFile); + if (m_url.isValid()) + return m_url.toString(QUrl::PreferLocalFile); + + return QString(); } QString PlacesItem::udi() const diff --git a/model/placesmodel.cpp b/model/placesmodel.cpp index 3956155..5b28c33 100644 --- a/model/placesmodel.cpp +++ b/model/placesmodel.cpp @@ -220,8 +220,12 @@ void PlacesModel::requestSetup(const int &index) Solid::Device device = Solid::Device(item->udi()); Solid::StorageAccess *access = device.as(); access->setup(); - connect(access, &Solid::StorageAccess::setupDone, this, [this, access]() { - emit deviceSetupDone(access->filePath()); + connect(access, &Solid::StorageAccess::setupDone, this, [this, item, access]() { + if (item) { + // 更新信息,让 qml 里的 sidebar 识别到 + item->setUrl(QUrl::fromLocalFile(access->filePath())); + emit deviceSetupDone(access->filePath()); + } }); } }