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.
This commit is contained in:
Jim Broadus 2020-06-18 15:14:08 -07:00 committed by John Maguire
parent 1ef5ec2590
commit 0d25a1b39c
1 changed files with 6 additions and 2 deletions

View File

@ -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());