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::deviceDiscovered, this, &BTDiscovery::btDeviceDiscovered);
|
||||||
connect(discoveryAgent, &QBluetoothDeviceDiscoveryAgent::finished, this, &BTDiscovery::btDeviceDiscoveryFinished);
|
connect(discoveryAgent, &QBluetoothDeviceDiscoveryAgent::finished, this, &BTDiscovery::btDeviceDiscoveryFinished);
|
||||||
connect(discoveryAgent, &QBluetoothDeviceDiscoveryAgent::canceled, 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),
|
connect(discoveryAgent, QOverload<QBluetoothDeviceDiscoveryAgent::Error>::of(&QBluetoothDeviceDiscoveryAgent::error),
|
||||||
|
#endif
|
||||||
[this](QBluetoothDeviceDiscoveryAgent::Error error){
|
[this](QBluetoothDeviceDiscoveryAgent::Error error){
|
||||||
qDebug() << "device discovery received error" << discoveryAgent->errorString();
|
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;
|
const char *uuid;
|
||||||
|
|
||||||
while ((uuid = array->uuid) != NULL) {
|
while ((uuid = array->uuid) != NULL) {
|
||||||
if (match == QUuid(uuid))
|
if (match == QBluetoothUuid(QUuid(uuid)))
|
||||||
return array->details;
|
return array->details;
|
||||||
array++;
|
array++;
|
||||||
}
|
}
|
||||||
|
@ -220,7 +220,11 @@ void BLEObject::addService(const QBluetoothUuid &newService)
|
||||||
service->connect(service, &QLowEnergyService::stateChanged,[=](QLowEnergyService::ServiceState newState) {
|
service->connect(service, &QLowEnergyService::stateChanged,[=](QLowEnergyService::ServiceState newState) {
|
||||||
qDebug() << " .. service state changed to" << 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),
|
service->connect(service, QOverload<QLowEnergyService::ServiceError>::of(&QLowEnergyService::error),
|
||||||
|
#endif
|
||||||
[=](QLowEnergyService::ServiceError newError) {
|
[=](QLowEnergyService::ServiceError newError) {
|
||||||
qDebug() << "error discovering service details" << 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
|
// Wait for each service to finish discovering
|
||||||
foreach (const QLowEnergyService *s, services) {
|
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);
|
WAITFOR(s->state() != QLowEnergyService::DiscoveringServices, BLE_TIMEOUT);
|
||||||
if (s->state() == QLowEnergyService::DiscoveringServices)
|
if (s->state() == QLowEnergyService::DiscoveringServices)
|
||||||
|
#endif
|
||||||
qDebug() << " .. service " << s->serviceUuid() << "still hasn't completed discovery - trouble ahead";
|
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
|
// Pick the preferred one
|
||||||
foreach (QLowEnergyService *s, services) {
|
foreach (QLowEnergyService *s, services) {
|
||||||
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||||
|
if (s->state() != QLowEnergyService::RemoteServiceDiscovered)
|
||||||
|
#else
|
||||||
if (s->state() != QLowEnergyService::ServiceDiscovered)
|
if (s->state() != QLowEnergyService::ServiceDiscovered)
|
||||||
|
#endif
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
bool hasread = false;
|
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);
|
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) {
|
ble->connect(controller, QOverload<QLowEnergyController::Error>::of(&QLowEnergyController::error), [=](QLowEnergyController::Error newError) {
|
||||||
|
#endif
|
||||||
qDebug() << "controler discovery error" << controller->errorString() << newError;
|
qDebug() << "controler discovery error" << controller->errorString() << newError;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -60,16 +60,16 @@ private:
|
||||||
unsigned int desc_written = 0;
|
unsigned int desc_written = 0;
|
||||||
int timeout;
|
int timeout;
|
||||||
|
|
||||||
QList<QUuid> telit = {
|
QList<QBluetoothUuid> telit = {
|
||||||
"{00000001-0000-1000-8000-008025000000}", // TELIT_DATA_RX
|
QBluetoothUuid(QUuid("{00000001-0000-1000-8000-008025000000}")), // TELIT_DATA_RX
|
||||||
"{00000002-0000-1000-8000-008025000000}", // TELIT_DATA_TX
|
QBluetoothUuid(QUuid("{00000002-0000-1000-8000-008025000000}")), // TELIT_DATA_TX
|
||||||
"{00000003-0000-1000-8000-008025000000}", // TELIT_CREDITS_RX
|
QBluetoothUuid(QUuid("{00000003-0000-1000-8000-008025000000}")), // TELIT_CREDITS_RX
|
||||||
"{00000004-0000-1000-8000-008025000000}" // TELIT_CREDITS_TX
|
QBluetoothUuid(QUuid("{00000004-0000-1000-8000-008025000000}")) // TELIT_CREDITS_TX
|
||||||
};
|
};
|
||||||
|
|
||||||
QList<QUuid> ublox = {
|
QList<QBluetoothUuid> ublox = {
|
||||||
"{2456e1b9-26e2-8f83-e744-f34f01e9d703}", // UBLOX_DATA_RX, UBLOX_DATA_TX
|
QBluetoothUuid(QUuid("{2456e1b9-26e2-8f83-e744-f34f01e9d703}")), // UBLOX_DATA_RX, UBLOX_DATA_TX
|
||||||
"{2456e1b9-26e2-8f83-e744-f34f01e9d704}" // UBLOX_CREDITS_RX, UBLOX_CREDITS_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);
|
ui->discoveredDevicesList->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||||
connect(ui->discoveredDevicesList, SIGNAL(customContextMenuRequested(QPoint)),
|
connect(ui->discoveredDevicesList, SIGNAL(customContextMenuRequested(QPoint)),
|
||||||
this, SLOT(displayPairingMenu(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)),
|
connect(localDevice, SIGNAL(pairingFinished(QBluetoothAddress, QBluetoothLocalDevice::Pairing)),
|
||||||
this, SLOT(pairingFinished(QBluetoothAddress, QBluetoothLocalDevice::Pairing)));
|
this, SLOT(pairingFinished(QBluetoothAddress, QBluetoothLocalDevice::Pairing)));
|
||||||
|
|
||||||
connect(localDevice, SIGNAL(error(QBluetoothLocalDevice::Error)),
|
connect(localDevice, SIGNAL(error(QBluetoothLocalDevice::Error)),
|
||||||
this, SLOT(error(QBluetoothLocalDevice::Error)));
|
this, SLOT(error(QBluetoothLocalDevice::Error)));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void BtDeviceSelectionDialog::initializeDeviceDiscoveryAgent()
|
void BtDeviceSelectionDialog::initializeDeviceDiscoveryAgent()
|
||||||
|
@ -494,10 +499,19 @@ void BtDeviceSelectionDialog::initializeDeviceDiscoveryAgent()
|
||||||
ui->clear->setEnabled(false);
|
ui->clear->setEnabled(false);
|
||||||
return;
|
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)),
|
connect(remoteDeviceDiscoveryAgent, SIGNAL(deviceDiscovered(QBluetoothDeviceInfo)),
|
||||||
this, SLOT(addRemoteDevice(QBluetoothDeviceInfo)));
|
this, SLOT(addRemoteDevice(QBluetoothDeviceInfo)));
|
||||||
connect(remoteDeviceDiscoveryAgent, SIGNAL(finished()),
|
connect(remoteDeviceDiscoveryAgent, SIGNAL(finished()),
|
||||||
this, SLOT(remoteDeviceScanFinished()));
|
this, SLOT(remoteDeviceScanFinished()));
|
||||||
connect(remoteDeviceDiscoveryAgent, SIGNAL(error(QBluetoothDeviceDiscoveryAgent::Error)),
|
connect(remoteDeviceDiscoveryAgent, SIGNAL(error(QBluetoothDeviceDiscoveryAgent::Error)),
|
||||||
this, SLOT(deviceDiscoveryError(QBluetoothDeviceDiscoveryAgent::Error)));
|
this, SLOT(deviceDiscoveryError(QBluetoothDeviceDiscoveryAgent::Error)));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue