@Paul-Colby Thanks for your reply again.
It would be interesting to try your code on Linux or macOS for comparison (they will also cache in lots of ways, but differently, so might be interesting).
I only tried the code on Linux for comparison (I don't have a macOS platform) and found that it didn't cache the service list. The application could find the OTA DATA characteristic after performing steps 1-3.
1.explicitly disconnecting the device - immediately after writing your characteristic, and/or immediately after receiving the disconnect signal (I'd try all combinations of either/both);
I tried all combinations on Windows 11, but none of them worked.
2.explicitly try to re-discover services after the initial discovery fails to find the new characteristic (the first discovery would register the WinRT BLE device with Qt, the second would close it before re-discovering).
I tried re-discover services and characteristics through two buttons, but none of them worked. The function QLowEnergyController::discoverServices() does nothing since it has been called immediately in the slot triggered by the QLowEnergyController::connected() signal. According to Qt help project, the best workaround is to temporarily turn Bluetooth off. So is it possible to turn Bluetooth off by code?
[image: bea2e7d2-6034-4a6c-96f0-41610a7f7e99.png]
[image: 1cf1ba81-1e8c-4d95-a59c-dacb57060fd2.png]
Anyway, it seems that the WinRT implementation does "clear the previous services cache" when (re)discovering services. However, it does this by iterating the currently known services, and closing them one by one.
Please see BluetoothLE example of Windows-universal-samples and the following codes (found at Windows Kits\10\Include\10.0.22621.0\cppwinrt\winrt):
template <typename D> WINRT_IMPL_AUTO(winrt::Windows::Foundation::IAsyncOperation<winrt::Windows::Devices::Bluetooth::GenericAttributeProfile::GattDeviceServicesResult>) consume_Windows_Devices_Bluetooth_IBluetoothLEDevice3<D>::GetGattServicesAsync(winrt::Windows::Devices::Bluetooth::BluetoothCacheMode const& cacheMode) const
{
void* operation{};
check_hresult(WINRT_IMPL_SHIM(winrt::Windows::Devices::Bluetooth::IBluetoothLEDevice3)->GetGattServicesWithCacheModeAsync(static_cast<int32_t>(cacheMode), &operation));
return winrt::Windows::Foundation::IAsyncOperation<winrt::Windows::Devices::Bluetooth::GenericAttributeProfile::GattDeviceServicesResult>{ operation, take_ownership_from_abi };
}
In QLowEnergyControllerPrivateWinRT: : discoverServices(), I think it should use GetGattServicesWithCacheModeAsync rather than GetGattServicesAsync. In obtainCharList, I think it should use GetCharacteristicsWithCacheModeAsync rather than GetCharacteristicsAsync. I have tried to modified the source codes (see the following pictures) and found it was worked. Now the application could find the OTA DATA characteristic after performing steps 1-3, but the speed of finding services and characteristics slowed down significantly.
[image: 134def9c-4600-4ac0-aca1-1aa34b2d2abc.png]
[image: f7b650fc-cdd5-4004-99dd-60547c66558c.png]
[image: 3c2d326d-d31c-4fce-b4ae-aa83b4a76861.png]