diff options
author | Marc Mutz <marc.mutz@qt.io> | 2023-08-02 14:18:09 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2023-08-02 18:04:31 +0200 |
commit | fa3fe7327250566ff77d3dc17fd3fff97e8ff725 (patch) | |
tree | c0f00fc134f7079ac203b5c754bd8ece6f06ad43 /examples | |
parent | e5a461ac978433a284cc8f4309fdfa326a34a2c0 (diff) |
ble example: fix namespaced builds
The forward declaration of class QLowEnergyService in bleiodevice.h
sits at global scope, so declares a second QLowEnergyService in
namespaced builds, and makes the following uses of the name ambiguous.
Unlike in the websockets example fixed in an earlier commit, here GCC
actually complains about the UB:
connectpage.cpp:129:21: required from here
qpointer.h:54:17: error: invalid ‘static_cast’ from type ‘QLowEnergyService*’ to type ‘Qt6::QPointer<QLowEnergyService>::QObjectType*’ {aka ‘Qt6::QObject*’}
54 | { wp.assign(static_cast<QObjectType*>(p)); return *this; }
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
connectpage.h:18:7: note: class type ‘QLowEnergyService’ is incomplete
18 | class QLowEnergyService;
| ^~~~~~~~~~~~~~~~~
Fix by replacing the forward declaration with an include.
The other types are actually used in-name-only, so keep the forward
declarations, but wrap them in QT_BEGIN_NAMESPACE/QT_END_NAMESPACE.
Add a missing <memory> include for unique_ptr.
Amends 846d26ca8ff95593aa44d32556b05da58ed94aa1.
Pick-to: 6.6 6.5
Change-Id: I277ca4896a8dc7fd8a36848c9caa352297635c05
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Diffstat (limited to 'examples')
4 files changed, 8 insertions, 2 deletions
diff --git a/examples/remoteobjects/ble/bleclient/connectpage.h b/examples/remoteobjects/ble/bleclient/connectpage.h index 044bedd..c189dd8 100644 --- a/examples/remoteobjects/ble/bleclient/connectpage.h +++ b/examples/remoteobjects/ble/bleclient/connectpage.h @@ -13,6 +13,7 @@ class BLEIoDevice; +QT_BEGIN_NAMESPACE class QBluetoothDeviceDiscoveryAgent; class QLowEnergyController; class QLowEnergyService; @@ -20,6 +21,7 @@ class QLowEnergyService; namespace Ui { class ConnectPage; } +QT_END_NAMESPACE class ConnectPage : public QWidget { diff --git a/examples/remoteobjects/ble/bleclient/heaterview.h b/examples/remoteobjects/ble/bleclient/heaterview.h index 8f7947d..b67c249 100644 --- a/examples/remoteobjects/ble/bleclient/heaterview.h +++ b/examples/remoteobjects/ble/bleclient/heaterview.h @@ -8,12 +8,16 @@ #include <QtRemoteObjects/QRemoteObjectNode> #include <QtWidgets/QWidget> +#include <memory> + class BLEIoDevice; class HeaterReplica; +QT_BEGIN_NAMESPACE namespace Ui { class HeaterView; } +QT_END_NAMESPACE class HeaterView : public QWidget { diff --git a/examples/remoteobjects/ble/common/bleiodevice.cpp b/examples/remoteobjects/ble/common/bleiodevice.cpp index ef71e70..f957495 100644 --- a/examples/remoteobjects/ble/common/bleiodevice.cpp +++ b/examples/remoteobjects/ble/common/bleiodevice.cpp @@ -5,7 +5,6 @@ #include "bleiodevice.h" #include <QtBluetooth/QLowEnergyController> -#include <QtBluetooth/QLowEnergyService> using namespace Qt::Literals::StringLiterals; diff --git a/examples/remoteobjects/ble/common/bleiodevice.h b/examples/remoteobjects/ble/common/bleiodevice.h index 64178ea..359913a 100644 --- a/examples/remoteobjects/ble/common/bleiodevice.h +++ b/examples/remoteobjects/ble/common/bleiodevice.h @@ -6,10 +6,11 @@ #include <QtBluetooth/QBluetoothUuid> #include <QtBluetooth/QLowEnergyCharacteristic> +#include <QtBluetooth/QLowEnergyService> + #include <QtCore/QIODevice> #include <QtCore/QPointer> -class QLowEnergyService; class BLEIoDevice : public QIODevice { Q_OBJECT |