diff options
Diffstat (limited to 'examples/knx/device/mainwindow.cpp')
-rw-r--r-- | examples/knx/device/mainwindow.cpp | 12 |
1 files changed, 9 insertions, 3 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(); |