mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Qt6: Bluetooth API changes
Use the explicit QBluetoothUuid instead of just QUuid and deal with new constants and signal names. At least with Qt6 we no longer need the ugly QOverload hack. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
78361ef8e3
commit
6f46238fc4
4 changed files with 44 additions and 9 deletions
|
@ -192,7 +192,11 @@ void BTDiscovery::BTDiscoveryReDiscover()
|
|||
connect(discoveryAgent, &QBluetoothDeviceDiscoveryAgent::deviceDiscovered, this, &BTDiscovery::btDeviceDiscovered);
|
||||
connect(discoveryAgent, &QBluetoothDeviceDiscoveryAgent::finished, this, &BTDiscovery::btDeviceDiscoveryFinished);
|
||||
connect(discoveryAgent, &QBluetoothDeviceDiscoveryAgent::canceled, this, &BTDiscovery::btDeviceDiscoveryFinished);
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
connect(discoveryAgent, &QBluetoothDeviceDiscoveryAgent::errorOccurred,
|
||||
#else
|
||||
connect(discoveryAgent, QOverload<QBluetoothDeviceDiscoveryAgent::Error>::of(&QBluetoothDeviceDiscoveryAgent::error),
|
||||
#endif
|
||||
[this](QBluetoothDeviceDiscoveryAgent::Error error){
|
||||
qDebug() << "device discovery received error" << discoveryAgent->errorString();
|
||||
});
|
||||
|
|
|
@ -110,7 +110,7 @@ static const char *match_uuid_list(const QBluetoothUuid &match, const struct uui
|
|||
const char *uuid;
|
||||
|
||||
while ((uuid = array->uuid) != NULL) {
|
||||
if (match == QUuid(uuid))
|
||||
if (match == QBluetoothUuid(QUuid(uuid)))
|
||||
return array->details;
|
||||
array++;
|
||||
}
|
||||
|
@ -220,7 +220,11 @@ void BLEObject::addService(const QBluetoothUuid &newService)
|
|||
service->connect(service, &QLowEnergyService::stateChanged,[=](QLowEnergyService::ServiceState newState) {
|
||||
qDebug() << " .. service state changed to" << newState;
|
||||
});
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
service->connect(service, &QLowEnergyService::errorOccurred,
|
||||
#else
|
||||
service->connect(service, QOverload<QLowEnergyService::ServiceError>::of(&QLowEnergyService::error),
|
||||
#endif
|
||||
[=](QLowEnergyService::ServiceError newError) {
|
||||
qDebug() << "error discovering service details" << newError;
|
||||
});
|
||||
|
@ -393,8 +397,13 @@ dc_status_t BLEObject::select_preferred_service(void)
|
|||
{
|
||||
// Wait for each service to finish discovering
|
||||
foreach (const QLowEnergyService *s, services) {
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
WAITFOR(s->state() != QLowEnergyService::RemoteServiceDiscovering, BLE_TIMEOUT);
|
||||
if (s->state() == QLowEnergyService::RemoteServiceDiscovering)
|
||||
#else
|
||||
WAITFOR(s->state() != QLowEnergyService::DiscoveringServices, BLE_TIMEOUT);
|
||||
if (s->state() == QLowEnergyService::DiscoveringServices)
|
||||
#endif
|
||||
qDebug() << " .. service " << s->serviceUuid() << "still hasn't completed discovery - trouble ahead";
|
||||
}
|
||||
|
||||
|
@ -412,7 +421,11 @@ dc_status_t BLEObject::select_preferred_service(void)
|
|||
|
||||
// Pick the preferred one
|
||||
foreach (QLowEnergyService *s, services) {
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
if (s->state() != QLowEnergyService::RemoteServiceDiscovered)
|
||||
#else
|
||||
if (s->state() != QLowEnergyService::ServiceDiscovered)
|
||||
#endif
|
||||
continue;
|
||||
|
||||
bool hasread = false;
|
||||
|
@ -604,7 +617,11 @@ dc_status_t qt_ble_open(void **io, dc_context_t *, const char *devaddr, device_d
|
|||
ble->addService(s);
|
||||
}
|
||||
});
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
ble->connect(controller, &QLowEnergyController::errorOccurred, [=](QLowEnergyController::Error newError) {
|
||||
#else
|
||||
ble->connect(controller, QOverload<QLowEnergyController::Error>::of(&QLowEnergyController::error), [=](QLowEnergyController::Error newError) {
|
||||
#endif
|
||||
qDebug() << "controler discovery error" << controller->errorString() << newError;
|
||||
});
|
||||
|
||||
|
|
|
@ -60,16 +60,16 @@ private:
|
|||
unsigned int desc_written = 0;
|
||||
int timeout;
|
||||
|
||||
QList<QUuid> telit = {
|
||||
"{00000001-0000-1000-8000-008025000000}", // TELIT_DATA_RX
|
||||
"{00000002-0000-1000-8000-008025000000}", // TELIT_DATA_TX
|
||||
"{00000003-0000-1000-8000-008025000000}", // TELIT_CREDITS_RX
|
||||
"{00000004-0000-1000-8000-008025000000}" // TELIT_CREDITS_TX
|
||||
QList<QBluetoothUuid> telit = {
|
||||
QBluetoothUuid(QUuid("{00000001-0000-1000-8000-008025000000}")), // TELIT_DATA_RX
|
||||
QBluetoothUuid(QUuid("{00000002-0000-1000-8000-008025000000}")), // TELIT_DATA_TX
|
||||
QBluetoothUuid(QUuid("{00000003-0000-1000-8000-008025000000}")), // TELIT_CREDITS_RX
|
||||
QBluetoothUuid(QUuid("{00000004-0000-1000-8000-008025000000}")) // TELIT_CREDITS_TX
|
||||
};
|
||||
|
||||
QList<QUuid> ublox = {
|
||||
"{2456e1b9-26e2-8f83-e744-f34f01e9d703}", // UBLOX_DATA_RX, UBLOX_DATA_TX
|
||||
"{2456e1b9-26e2-8f83-e744-f34f01e9d704}" // UBLOX_CREDITS_RX, UBLOX_CREDITS_TX
|
||||
QList<QBluetoothUuid> ublox = {
|
||||
QBluetoothUuid(QUuid("{2456e1b9-26e2-8f83-e744-f34f01e9d703}")), // UBLOX_DATA_RX, UBLOX_DATA_TX
|
||||
QBluetoothUuid(QUuid("{2456e1b9-26e2-8f83-e744-f34f01e9d704}")) // UBLOX_CREDITS_RX, UBLOX_CREDITS_TX
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -473,11 +473,16 @@ void BtDeviceSelectionDialog::updateLocalDeviceInformation()
|
|||
ui->discoveredDevicesList->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
connect(ui->discoveredDevicesList, SIGNAL(customContextMenuRequested(QPoint)),
|
||||
this, SLOT(displayPairingMenu(QPoint)));
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
connect(localDevice, &QBluetoothLocalDevice::pairingFinished, this, &BtDeviceSelectionDialog::pairingFinished);
|
||||
connect(localDevice, &QBluetoothLocalDevice::errorOccurred, this, &BtDeviceSelectionDialog::error);
|
||||
#else
|
||||
connect(localDevice, SIGNAL(pairingFinished(QBluetoothAddress, QBluetoothLocalDevice::Pairing)),
|
||||
this, SLOT(pairingFinished(QBluetoothAddress, QBluetoothLocalDevice::Pairing)));
|
||||
|
||||
connect(localDevice, SIGNAL(error(QBluetoothLocalDevice::Error)),
|
||||
this, SLOT(error(QBluetoothLocalDevice::Error)));
|
||||
#endif
|
||||
}
|
||||
|
||||
void BtDeviceSelectionDialog::initializeDeviceDiscoveryAgent()
|
||||
|
@ -494,10 +499,19 @@ void BtDeviceSelectionDialog::initializeDeviceDiscoveryAgent()
|
|||
ui->clear->setEnabled(false);
|
||||
return;
|
||||
}
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
connect(remoteDeviceDiscoveryAgent, &QBluetoothDeviceDiscoveryAgent::deviceDiscovered,
|
||||
this, &BtDeviceSelectionDialog::addRemoteDevice);
|
||||
connect(remoteDeviceDiscoveryAgent, &QBluetoothDeviceDiscoveryAgent::finished,
|
||||
this, &BtDeviceSelectionDialog::remoteDeviceScanFinished);
|
||||
connect(remoteDeviceDiscoveryAgent, &QBluetoothDeviceDiscoveryAgent::errorOccurred,
|
||||
this, &BtDeviceSelectionDialog::deviceDiscoveryError);
|
||||
#else
|
||||
connect(remoteDeviceDiscoveryAgent, SIGNAL(deviceDiscovered(QBluetoothDeviceInfo)),
|
||||
this, SLOT(addRemoteDevice(QBluetoothDeviceInfo)));
|
||||
connect(remoteDeviceDiscoveryAgent, SIGNAL(finished()),
|
||||
this, SLOT(remoteDeviceScanFinished()));
|
||||
connect(remoteDeviceDiscoveryAgent, SIGNAL(error(QBluetoothDeviceDiscoveryAgent::Error)),
|
||||
this, SLOT(deviceDiscoveryError(QBluetoothDeviceDiscoveryAgent::Error)));
|
||||
#endif
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue