From 617c6d3564e562df580824280654d9edaf238084 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sat, 4 Nov 2017 15:09:07 +0100 Subject: Replace itemClicked() by currentItemChanged() in Bt device selection This fixes two problems: 1) Using the keybord or clicking below the list and moving the mouse up while holding the mouse button did not properly update the status message and the save button. For example, one could save with a non- paired device selected. 2) The code assumed that a device is selected if the save button is active, but the save button was not disabled on scan. Thus, one could provoke a crash by selecting an item, scanning and then pressing save. This problem is fixed indirectly, because the save button is now always disabled if the selection is cleared. Signed-off-by: Berthold Stoeger --- desktop-widgets/btdeviceselectiondialog.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'desktop-widgets/btdeviceselectiondialog.cpp') diff --git a/desktop-widgets/btdeviceselectiondialog.cpp b/desktop-widgets/btdeviceselectiondialog.cpp index cf70daa3f..74ce44cb1 100644 --- a/desktop-widgets/btdeviceselectiondialog.cpp +++ b/desktop-widgets/btdeviceselectiondialog.cpp @@ -46,8 +46,8 @@ BtDeviceSelectionDialog::BtDeviceSelectionDialog(QWidget *parent) : ui->save->setEnabled(false); // Add event for item selection - connect(ui->discoveredDevicesList, SIGNAL(itemClicked(QListWidgetItem*)), - this, SLOT(itemClicked(QListWidgetItem*))); + connect(ui->discoveredDevicesList, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), + this, SLOT(currentItemChanged(QListWidgetItem*,QListWidgetItem*))); #if defined(Q_OS_WIN) ULONG ulRetCode = SUCCESS; @@ -172,7 +172,6 @@ void BtDeviceSelectionDialog::on_clear_clicked() { ui->dialogStatus->setText(tr("Remote devices list was cleared.")); ui->discoveredDevicesList->clear(); - ui->save->setEnabled(false); if (remoteDeviceDiscoveryAgent->isActive()) { // Stop the SDP agent if the clear button is pressed and enable the Scan button @@ -263,8 +262,14 @@ void BtDeviceSelectionDialog::addRemoteDevice(const QBluetoothDeviceInfo &remote ui->discoveredDevicesList->addItem(item); } -void BtDeviceSelectionDialog::itemClicked(QListWidgetItem *item) +void BtDeviceSelectionDialog::currentItemChanged(QListWidgetItem *item, QListWidgetItem *) { + // If the list is cleared, we get a signal with a null item pointer + if (!item) { + ui->save->setEnabled(false); + return; + } + // By default we assume that the devices are paired QBluetoothDeviceInfo remoteDeviceInfo = item->data(Qt::UserRole).value(); QString statusMessage = tr("The device %1 can be used for connection. You can press the Save button.") -- cgit v1.2.3-70-g09d2