diff options
author | Oliver Wolff <oliver.wolff@qt.io> | 2022-01-26 10:31:25 +0100 |
---|---|---|
committer | Oliver Wolff <oliver.wolff@qt.io> | 2022-01-26 13:07:46 +0100 |
commit | 215b7bea7666ee1c428b034fe0aa1c6beff4b618 (patch) | |
tree | 6ce7f7378146860a52884b19fddc78e9156cbf74 /examples | |
parent | 69b4123451d3dcc93b998bd38b0cdd772cbcb924 (diff) |
btscanner example: Add option to stop a running scan
Change-Id: Id82f6c903938e289559a79b4a2383ad20944c61a
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Diffstat (limited to 'examples')
-rw-r--r-- | examples/bluetooth/btscanner/device.cpp | 14 | ||||
-rw-r--r-- | examples/bluetooth/btscanner/device.h | 1 | ||||
-rw-r--r-- | examples/bluetooth/btscanner/device.ui | 7 |
3 files changed, 20 insertions, 2 deletions
diff --git a/examples/bluetooth/btscanner/device.cpp b/examples/bluetooth/btscanner/device.cpp index 33e29e07..82c1f846 100644 --- a/examples/bluetooth/btscanner/device.cpp +++ b/examples/bluetooth/btscanner/device.cpp @@ -72,6 +72,7 @@ DeviceDiscoveryDialog::DeviceDiscoveryDialog(QWidget *parent) : ui(new Ui_DeviceDiscovery) { ui->setupUi(this); + ui->stopScan->setVisible(false); // In case of multiple Bluetooth adapters it is possible to set the adapter // to be used. Example code: @@ -82,6 +83,7 @@ DeviceDiscoveryDialog::DeviceDiscoveryDialog(QWidget *parent) : discoveryAgent = new QBluetoothDeviceDiscoveryAgent(); connect(ui->scan, &QAbstractButton::clicked, this, &DeviceDiscoveryDialog::startScan); + connect(ui->stopScan, &QAbstractButton::clicked, this, &DeviceDiscoveryDialog::stopScan); connect(discoveryAgent, &QBluetoothDeviceDiscoveryAgent::deviceDiscovered, this, &DeviceDiscoveryDialog::addDevice); @@ -123,12 +125,20 @@ void DeviceDiscoveryDialog::addDevice(const QBluetoothDeviceInfo &info) void DeviceDiscoveryDialog::startScan() { discoveryAgent->start(); - ui->scan->setEnabled(false); + ui->scan->setVisible(false); + ui->stopScan->setVisible(true); +} + +void DeviceDiscoveryDialog::stopScan() +{ + discoveryAgent->stop(); + scanFinished(); } void DeviceDiscoveryDialog::scanFinished() { - ui->scan->setEnabled(true); + ui->scan->setVisible(true); + ui->stopScan->setVisible(false); } void DeviceDiscoveryDialog::itemActivated(QListWidgetItem *item) diff --git a/examples/bluetooth/btscanner/device.h b/examples/bluetooth/btscanner/device.h index 0bad0361..440851c9 100644 --- a/examples/bluetooth/btscanner/device.h +++ b/examples/bluetooth/btscanner/device.h @@ -79,6 +79,7 @@ public slots: void pairingDone(const QBluetoothAddress&, QBluetoothLocalDevice::Pairing); private slots: void startScan(); + void stopScan(); void scanFinished(); void itemActivated(QListWidgetItem *item); void hostModeStateChanged(QBluetoothLocalDevice::HostMode); diff --git a/examples/bluetooth/btscanner/device.ui b/examples/bluetooth/btscanner/device.ui index fa81c5cb..fd86a358 100644 --- a/examples/bluetooth/btscanner/device.ui +++ b/examples/bluetooth/btscanner/device.ui @@ -56,6 +56,13 @@ </widget> </item> <item> + <widget class="QPushButton" name="stopScan"> + <property name="text"> + <string>Stop scan</string> + </property> + </widget> + </item> + <item> <widget class="QPushButton" name="clear"> <property name="text"> <string>Clear</string> |