From a1e00ab195e879724efb0c03be8c06ddb6799fac Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Thu, 30 Aug 2018 10:20:01 +0200 Subject: Fix a few clazy/clang warnings in HeartRate Game example Change-Id: I2a7b8c403ca466998ddcbd8496c31feb9856f0ad Reviewed-by: Timur Pocheptsov --- .../bluetooth/heartrate-game/bluetoothbaseclass.h | 2 +- examples/bluetooth/heartrate-game/connectionhandler.h | 2 +- examples/bluetooth/heartrate-game/devicefinder.cpp | 13 +++++++------ examples/bluetooth/heartrate-game/devicefinder.h | 5 +++-- examples/bluetooth/heartrate-game/devicehandler.cpp | 19 ++++++++----------- examples/bluetooth/heartrate-game/devicehandler.h | 11 ++++++----- examples/bluetooth/heartrate-game/deviceinfo.cpp | 2 +- examples/bluetooth/heartrate-game/main.cpp | 4 ++-- 8 files changed, 29 insertions(+), 29 deletions(-) (limited to 'examples/bluetooth') diff --git a/examples/bluetooth/heartrate-game/bluetoothbaseclass.h b/examples/bluetooth/heartrate-game/bluetoothbaseclass.h index 74fe4576..5a043b3d 100644 --- a/examples/bluetooth/heartrate-game/bluetoothbaseclass.h +++ b/examples/bluetooth/heartrate-game/bluetoothbaseclass.h @@ -60,7 +60,7 @@ class BluetoothBaseClass : public QObject Q_PROPERTY(QString info READ info WRITE setInfo NOTIFY infoChanged) public: - explicit BluetoothBaseClass(QObject *parent = 0); + explicit BluetoothBaseClass(QObject *parent = nullptr); QString error() const; void setError(const QString& error); diff --git a/examples/bluetooth/heartrate-game/connectionhandler.h b/examples/bluetooth/heartrate-game/connectionhandler.h index b4280978..9f5a42cc 100644 --- a/examples/bluetooth/heartrate-game/connectionhandler.h +++ b/examples/bluetooth/heartrate-game/connectionhandler.h @@ -63,7 +63,7 @@ class ConnectionHandler : public QObject Q_OBJECT public: - explicit ConnectionHandler(QObject *parent = 0); + explicit ConnectionHandler(QObject *parent = nullptr); bool alive() const; bool requiresAddressType() const; diff --git a/examples/bluetooth/heartrate-game/devicefinder.cpp b/examples/bluetooth/heartrate-game/devicefinder.cpp index 38f538e9..19ebee90 100644 --- a/examples/bluetooth/heartrate-game/devicefinder.cpp +++ b/examples/bluetooth/heartrate-game/devicefinder.cpp @@ -85,7 +85,7 @@ DeviceFinder::~DeviceFinder() void DeviceFinder::startSearch() { clearMessages(); - m_deviceHandler->setDevice(0); + m_deviceHandler->setDevice(nullptr); qDeleteAll(m_devices); m_devices.clear(); @@ -135,7 +135,7 @@ void DeviceFinder::scanFinished() m_devices.append(new DeviceInfo(QBluetoothDeviceInfo())); #endif - if (m_devices.size() == 0) + if (m_devices.isEmpty()) setError(tr("No Low Energy devices found.")); else setInfo(tr("Scanning done.")); @@ -148,10 +148,11 @@ void DeviceFinder::connectToService(const QString &address) { m_deviceDiscoveryAgent->stop(); - DeviceInfo *currentDevice = 0; - for (int i = 0; i < m_devices.size(); i++) { - if (((DeviceInfo*)m_devices.at(i))->getAddress() == address ) { - currentDevice = (DeviceInfo*)m_devices.at(i); + DeviceInfo *currentDevice = nullptr; + for (QObject *entry : qAsConst(m_devices)) { + auto device = qobject_cast(entry); + if (device && device->getAddress() == address ) { + currentDevice = device; break; } } diff --git a/examples/bluetooth/heartrate-game/devicefinder.h b/examples/bluetooth/heartrate-game/devicefinder.h index 2c54f550..6dbb5692 100644 --- a/examples/bluetooth/heartrate-game/devicefinder.h +++ b/examples/bluetooth/heartrate-game/devicefinder.h @@ -55,9 +55,10 @@ #include "bluetoothbaseclass.h" #include +#include #include #include -#include + class DeviceInfo; class DeviceHandler; @@ -70,7 +71,7 @@ class DeviceFinder: public BluetoothBaseClass Q_PROPERTY(QVariant devices READ devices NOTIFY devicesChanged) public: - DeviceFinder(DeviceHandler *handler, QObject *parent = 0); + DeviceFinder(DeviceHandler *handler, QObject *parent = nullptr); ~DeviceFinder(); bool scanning() const; diff --git a/examples/bluetooth/heartrate-game/devicehandler.cpp b/examples/bluetooth/heartrate-game/devicehandler.cpp index 3bbadd7e..83a4fbbe 100644 --- a/examples/bluetooth/heartrate-game/devicehandler.cpp +++ b/examples/bluetooth/heartrate-game/devicehandler.cpp @@ -56,9 +56,6 @@ DeviceHandler::DeviceHandler(QObject *parent) : BluetoothBaseClass(parent), - m_control(0), - m_service(0), - m_currentDevice(0), m_foundHeartRateService(false), m_measuring(false), m_currentValue(0), @@ -107,7 +104,7 @@ void DeviceHandler::setDevice(DeviceInfo *device) if (m_control) { m_control->disconnectFromDevice(); delete m_control; - m_control = 0; + m_control = nullptr; } // Create new controller and connect it if device available @@ -181,7 +178,7 @@ void DeviceHandler::serviceScanDone() // Delete old service if available if (m_service) { delete m_service; - m_service = 0; + m_service = nullptr; } //! [Filter HeartRate service 2] @@ -240,15 +237,15 @@ void DeviceHandler::updateHeartRateValue(const QLowEnergyCharacteristic &c, cons if (c.uuid() != QBluetoothUuid(QBluetoothUuid::HeartRateMeasurement)) return; - const quint8 *data = reinterpret_cast(value.constData()); - quint8 flags = data[0]; + auto data = reinterpret_cast(value.constData()); + quint8 flags = *data; //Heart Rate int hrvalue = 0; if (flags & 0x1) // HR 16 bit? otherwise 8 bit - hrvalue = (int)qFromLittleEndian(data[1]); + hrvalue = static_cast(qFromLittleEndian(data[1])); else - hrvalue = (int)data[1]; + hrvalue = static_cast(data[1]); addMeasurement(hrvalue); } @@ -276,7 +273,7 @@ void DeviceHandler::confirmedDescriptorWrite(const QLowEnergyDescriptor &d, cons //disabled notifications -> assume disconnect intent m_control->disconnectFromDevice(); delete m_service; - m_service = 0; + m_service = nullptr; } } @@ -293,7 +290,7 @@ void DeviceHandler::disconnectService() m_control->disconnectFromDevice(); delete m_service; - m_service = 0; + m_service = nullptr; } } diff --git a/examples/bluetooth/heartrate-game/devicehandler.h b/examples/bluetooth/heartrate-game/devicehandler.h index 05984ea5..4fa2782b 100644 --- a/examples/bluetooth/heartrate-game/devicehandler.h +++ b/examples/bluetooth/heartrate-game/devicehandler.h @@ -54,8 +54,9 @@ #include "bluetoothbaseclass.h" #include -#include #include +#include + #include #include @@ -82,7 +83,7 @@ public: }; Q_ENUM(AddressType) - DeviceHandler(QObject *parent = 0); + DeviceHandler(QObject *parent = nullptr); void setDevice(DeviceInfo *device); void setAddressType(AddressType type); @@ -127,10 +128,10 @@ private: private: void addMeasurement(int value); - QLowEnergyController *m_control; - QLowEnergyService *m_service; + QLowEnergyController *m_control = nullptr; + QLowEnergyService *m_service = nullptr; QLowEnergyDescriptor m_notificationDesc; - DeviceInfo *m_currentDevice; + DeviceInfo *m_currentDevice = nullptr; bool m_foundHeartRateService; bool m_measuring; diff --git a/examples/bluetooth/heartrate-game/deviceinfo.cpp b/examples/bluetooth/heartrate-game/deviceinfo.cpp index 3925ce66..4ed7f1b1 100644 --- a/examples/bluetooth/heartrate-game/deviceinfo.cpp +++ b/examples/bluetooth/heartrate-game/deviceinfo.cpp @@ -54,7 +54,7 @@ #include DeviceInfo::DeviceInfo(const QBluetoothDeviceInfo &info): - QObject(), m_device(info) + m_device(info) { } diff --git a/examples/bluetooth/heartrate-game/main.cpp b/examples/bluetooth/heartrate-game/main.cpp index 33760e9d..099f82a7 100644 --- a/examples/bluetooth/heartrate-game/main.cpp +++ b/examples/bluetooth/heartrate-game/main.cpp @@ -49,9 +49,9 @@ ****************************************************************************/ #include +#include #include #include -#include #include "connectionhandler.h" #include "devicefinder.h" @@ -59,7 +59,7 @@ int main(int argc, char *argv[]) { - //QLoggingCategory::setFilterRules(QStringLiteral("qt.bluetooth* = true")); + QLoggingCategory::setFilterRules(QStringLiteral("qt.bluetooth* = true")); QGuiApplication app(argc, argv); ConnectionHandler connectionHandler; -- cgit v1.2.3