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