@J-Hilk Thank you, JonB and you were right. For me it actually makes more sense that e.g. at first you connect to the device and then you say "okay, if the signal "connected" is emitted then call the function x.y.". So after changing it, it works now. However, after getting all services and calling "service->discoverDetails" and then "service->characteristics" the characteristics List is empty.
After connection is successfull:
void Scanner::startServiceDiscovery(){
connect(controller, &QLowEnergyController::discoveryFinished, this, &Scanner::discoveryFinished);
controller->discoverServices();
}
void Scanner::discoveryFinished(){
qDebug() << "\nService Discovery finished. Following Services found:\n";
QList<QBluetoothUuid> serviceList = controller->services();
for(QBluetoothUuid &sl : serviceList){
qDebug() << controller->createServiceObject(sl)->serviceName() << "Uuid: " << sl;
}
uartService = controller->createServiceObject(adafruitServiceUuid);
qDebug() <<"\nChose the following service: " << (*uartService).serviceName();
connect(uartService, &QLowEnergyService::stateChanged, this, &Scanner::printChars);
qDebug() << uartService->state(); //here the state is QLowEnergyService::DiscoveryRequired
uartService->discoverDetails();
}
void Scanner::printChars(){
qDebug() << uartService->state(); // here the state is now QLowEnergyService::DiscoveringServices
const QList<QLowEnergyCharacteristic> chars = uartService->characteristics();
qDebug()<< chars.size(); //however the list size is 0
for (const QLowEnergyCharacteristic &ch : chars) {
qDebug() << &ch;
}
}
btw: I know that there is an example for BLE Scanner. But for a project, I want to create an own desktop application which connnects to a peripheral and live plots the data which are received from the sensor with qcustomplot. So I need a QWidget Application because QCustomPlot is a widget...