From 78746824e2a46914eb9d919306b5919c8b03588b Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Fri, 6 Jul 2018 00:42:07 -0700 Subject: [PATCH] Fix inconsistent ComputerModel view of the ComputerManager's state after new PC is added --- app/gui/computermodel.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/app/gui/computermodel.cpp b/app/gui/computermodel.cpp index 7c5202d7..2f13ddab 100644 --- a/app/gui/computermodel.cpp +++ b/app/gui/computermodel.cpp @@ -121,13 +121,12 @@ void ComputerModel::handleComputerStateChanged(NvComputer* computer) emit dataChanged(createIndex(index, 0), createIndex(index, 0)); } else { - // This is a new PC that will be inserted at the end - beginInsertRows(QModelIndex(), m_Computers.count(), m_Computers.count()); - m_Computers.append(computer); - endInsertRows(); + // This is a new PC which may be inserted at an arbitrary point + // in our computer list (since it comes from CM's QMap). Reload + // the whole model state to ensure it stays consistent. + beginResetModel(); + m_Computers = m_ComputerManager->getComputers(); + endResetModel(); } - - // Our view of the world must be in sync with ComputerManager's - Q_ASSERT(m_Computers.count() == m_ComputerManager->getComputers().count()); }