Skip to content

Commit

Permalink
Properly delete ignored DeviceInfo object
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jbroadus authored and hatstand committed Jun 18, 2020
1 parent 1ef5ec2 commit 0d25a1b
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/devices/devicemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit 0d25a1b

Please sign in to comment.