From 0d25a1b39cfb82ff62a0de23a8991ed9c8152214 Mon Sep 17 00:00:00 2001 From: Jim Broadus Date: Thu, 18 Jun 2020 15:14:08 -0700 Subject: [PATCH] Properly delete ignored DeviceInfo object Since the SimpleTreeItem constructor variant used from LoadAllDevices adds the object to the parent's children list, use the parent's Delete method to destroy it. --- src/devices/devicemanager.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/devices/devicemanager.cpp b/src/devices/devicemanager.cpp index ece243ecc..c9cdf745a 100644 --- a/src/devices/devicemanager.cpp +++ b/src/devices/devicemanager.cpp @@ -136,6 +136,7 @@ DeviceManager::~DeviceManager() { delete root_; } +// This runs concurrently. void DeviceManager::LoadAllDevices() { Q_ASSERT(QThread::currentThread() != qApp->thread()); DeviceDatabaseBackend::DeviceList devices = backend_->GetAllDevices(); @@ -166,8 +167,11 @@ void DeviceManager::AddDeviceFromDb(DeviceInfo* info) { existing->icon_ = info->icon_; QModelIndex idx = ItemToIndex(existing); if (idx.isValid()) emit dataChanged(idx, idx); - // Discard the info loaded from the database. - delete info; + + // Discard the info loaded from the database. This doesn't use + // begin/endRemoveRows, but beginInsertRows has not yet been called to + // notify listeners of the existence. + root_->Delete(info->row); } else { qLog(Info) << "Device added from database: " << info->friendly_name_; beginInsertRows(ItemToIndex(root_), devices_.count(), devices_.count());