From 89540e0fb2051b667135e2588e70b8ad49f61cd4 Mon Sep 17 00:00:00 2001 From: Claudiu Olteanu Date: Sat, 19 Sep 2015 19:14:51 +0300 Subject: [PATCH] Fix Bluetooth address truncation issues on Windows On some Windows platforms when we convert a Bth address to a String it is formatted as "(XX:XX:XX:XX:XX:XX)". Therefore we first try to remove the round parentheses and finally we truncate the string to 17 because there are 6 two-digit hex values and 5 colons. Signed-off-by: Claudiu Olteanu Signed-off-by: Dirk Hohndel --- qt-ui/btdeviceselectiondialog.cpp | 8 ++++---- qt-ui/btdeviceselectiondialog.h | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/qt-ui/btdeviceselectiondialog.cpp b/qt-ui/btdeviceselectiondialog.cpp index 74afda616..40d57314f 100644 --- a/qt-ui/btdeviceselectiondialog.cpp +++ b/qt-ui/btdeviceselectiondialog.cpp @@ -609,14 +609,14 @@ void WinBluetoothDeviceDiscoveryAgent::run() break; } - // Save the name of the discovered device and truncate the address - QString deviceName = QString(pResults->lpszServiceInstanceName); - deviceAddress.truncate(addressSize / sizeof(wchar_t)); - // Remove the round parentheses deviceAddress.remove(')'); deviceAddress.remove('('); + // Save the name of the discovered device and truncate the address + QString deviceName = QString(pResults->lpszServiceInstanceName); + deviceAddress.truncate(BTH_ADDR_PRETTY_STRING_LEN); + // Create an object with information about the discovered device QBluetoothDeviceInfo deviceInfo = QBluetoothDeviceInfo(QBluetoothAddress(deviceAddress), deviceName, 0); diff --git a/qt-ui/btdeviceselectiondialog.h b/qt-ui/btdeviceselectiondialog.h index 3d72db418..d947d3449 100644 --- a/qt-ui/btdeviceselectiondialog.h +++ b/qt-ui/btdeviceselectiondialog.h @@ -15,6 +15,7 @@ #define SUCCESS 0 #define BTH_ADDR_STR_LEN 40 + #define BTH_ADDR_PRETTY_STRING_LEN 17 // there are 6 two-digit hex values and 5 colons #undef ERROR // this is already declared in our headers #undef IGNORE // this is already declared in our headers