From 9e62540f0fd0d7453f46e00122642a298cd4e8fe Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Tue, 10 Aug 2021 23:43:31 +0200 Subject: [PATCH] Fix current index in main menu after a setup is aborted --- nymea-app/configuredhostsmodel.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/nymea-app/configuredhostsmodel.cpp b/nymea-app/configuredhostsmodel.cpp index d01dc82c..11877c7a 100644 --- a/nymea-app/configuredhostsmodel.cpp +++ b/nymea-app/configuredhostsmodel.cpp @@ -17,8 +17,8 @@ ConfiguredHostsModel::ConfiguredHostsModel(QObject *parent) : QAbstractListModel host->setName(cachedName); addHost(host); settings.endGroup(); - m_currentIndex = settings.value("currentIndex", 0).toInt(); } + m_currentIndex = settings.value("currentIndex", 0).toInt(); settings.endGroup(); // If there aren't any in the config, try migrating settings from old tab model @@ -42,6 +42,11 @@ ConfiguredHostsModel::ConfiguredHostsModel(QObject *parent) : QAbstractListModel if (m_list.isEmpty()) { createHost(); } + + // Make sure the currentIndex from the config isn't out of place + if (m_currentIndex >= m_list.count()) { + m_currentIndex = m_list.count()-1; + } } int ConfiguredHostsModel::rowCount(const QModelIndex &parent) const