summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarsten Heimrich <karsten.heimrich@qt.io>2019-08-16 09:26:25 +0200
committerKarsten Heimrich <karsten.heimrich@qt.io>2019-08-20 15:53:43 +0200
commit677de500f64aa23c4bf552eb1bbba7b98def6562 (patch)
treeb6b7f988e4a37dda4c7bc5b8fcb55a45fcaa7533
parentf72347f423c950524ae4a2837c69b68736294685 (diff)
Fix crash accessing the device model with negative index
Change-Id: Ifb1a5fee3e9f2f629f16902bd5fd3b6051c3c4f8 Reviewed-by: Karsten Heimrich <karsten.heimrich@qt.io>
-rw-r--r--examples/knx/device/mainwindow.cpp12
-rw-r--r--examples/knx/feature/mainwindow.cpp12
-rw-r--r--examples/knx/group/mainwindow.cpp12
3 files changed, 27 insertions, 9 deletions
diff --git a/examples/knx/device/mainwindow.cpp b/examples/knx/device/mainwindow.cpp
index 54d3b6a..f1516a2 100644
--- a/examples/knx/device/mainwindow.cpp
+++ b/examples/knx/device/mainwindow.cpp
@@ -170,13 +170,16 @@ void MainWindow::on_actionImport_triggered()
on_devices_currentIndexChanged(ui->devices->currentIndex());
}
-void MainWindow::on_devices_currentIndexChanged(int /* index */)
+void MainWindow::on_devices_currentIndexChanged(int index)
{
delete m_device;
+ m_device = nullptr;
ui->secureConfigs->clear();
- const auto model = qobject_cast<QStandardItemModel*>(ui->devices->model());
- m_device = static_cast<DeviceItem *> (model->item(ui->devices->currentIndex()))->clone();
+ if (index >= 0) {
+ const auto model = qobject_cast<QStandardItemModel*>(ui->devices->model());
+ m_device = static_cast<DeviceItem *> (model->item(ui->devices->currentIndex()))->clone();
+ }
if (m_device) {
const auto deviceInfo = m_device->info();
@@ -190,6 +193,8 @@ void MainWindow::on_devices_currentIndexChanged(int /* index */)
.arg(config.userId())
.arg(ia.isValid() ? ia.toString() : tr("No specific address")), i);
}
+ } else {
+ m_device = new DeviceItem({});
}
ui->secureConfigs->setEnabled(bool(ui->secureConfigs->count())
@@ -311,6 +316,7 @@ void MainWindow::setupInterfaces()
if (i < 0)
return;
m_discoveryAgent.stop();
+ ui->devices->clear();
m_discoveryAgent.setLocalAddress(QHostAddress(ui->interfaces->currentData()
.toStringList().first()));
m_discoveryAgent.start();
diff --git a/examples/knx/feature/mainwindow.cpp b/examples/knx/feature/mainwindow.cpp
index 7e44327..8f32b06 100644
--- a/examples/knx/feature/mainwindow.cpp
+++ b/examples/knx/feature/mainwindow.cpp
@@ -170,13 +170,16 @@ void MainWindow::on_actionImport_triggered()
on_devices_currentIndexChanged(ui->devices->currentIndex());
}
-void MainWindow::on_devices_currentIndexChanged(int /* index */)
+void MainWindow::on_devices_currentIndexChanged(int index)
{
delete m_device;
+ m_device = nullptr;
ui->secureConfigs->clear();
- const auto model = qobject_cast<QStandardItemModel*>(ui->devices->model());
- m_device = static_cast<DeviceItem *> (model->item(ui->devices->currentIndex()))->clone();
+ if (index >= 0) {
+ const auto model = qobject_cast<QStandardItemModel*>(ui->devices->model());
+ m_device = static_cast<DeviceItem *> (model->item(ui->devices->currentIndex()))->clone();
+ }
if (m_device) {
const auto deviceInfo = m_device->info();
@@ -190,6 +193,8 @@ void MainWindow::on_devices_currentIndexChanged(int /* index */)
.arg(config.userId())
.arg(ia.isValid() ? ia.toString() : tr("No specific address")), i);
}
+ } else {
+ m_device = new DeviceItem({});
}
ui->secureConfigs->setEnabled(bool(ui->secureConfigs->count())
@@ -280,6 +285,7 @@ void MainWindow::setupInterfaces()
if (i < 0)
return;
m_discoveryAgent.stop();
+ ui->devices->clear();
m_discoveryAgent.setLocalAddress(QHostAddress(ui->interfaces->currentData()
.toStringList().first()));
m_discoveryAgent.start();
diff --git a/examples/knx/group/mainwindow.cpp b/examples/knx/group/mainwindow.cpp
index 4100e03..2e297af 100644
--- a/examples/knx/group/mainwindow.cpp
+++ b/examples/knx/group/mainwindow.cpp
@@ -169,13 +169,16 @@ void MainWindow::on_actionImport_triggered()
on_devices_currentIndexChanged(ui->devices->currentIndex());
}
-void MainWindow::on_devices_currentIndexChanged(int /* index */)
+void MainWindow::on_devices_currentIndexChanged(int index)
{
delete m_device;
+ m_device = nullptr;
ui->secureConfigs->clear();
- const auto model = qobject_cast<QStandardItemModel*>(ui->devices->model());
- m_device = static_cast<DeviceItem *> (model->item(ui->devices->currentIndex()))->clone();
+ if (index >= 0) {
+ const auto model = qobject_cast<QStandardItemModel*>(ui->devices->model());
+ m_device = static_cast<DeviceItem *> (model->item(ui->devices->currentIndex()))->clone();
+ }
if (m_device) {
const auto deviceInfo = m_device->info();
@@ -189,6 +192,8 @@ void MainWindow::on_devices_currentIndexChanged(int /* index */)
.arg(config.userId())
.arg(ia.isValid() ? ia.toString() : tr("No specific address")), i);
}
+ } else {
+ m_device = new DeviceItem({});
}
ui->secureConfigs->setEnabled(bool(ui->secureConfigs->count())
@@ -288,6 +293,7 @@ void MainWindow::setupInterfaces()
if (i < 0)
return;
m_discoveryAgent.stop();
+ ui->devices->clear();
m_discoveryAgent.setLocalAddress(QHostAddress(ui->interfaces->currentData()
.toStringList().first()));
m_discoveryAgent.start();