summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2022-05-20 18:36:48 +0200
committerGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2022-05-21 11:43:59 +0200
commitc613dd4765637a00837dd66abc2b940632022a60 (patch)
treec7abdbd920f7ccb157e440fc36eceb14021380e1 /tests/auto
parent3d9e56aa6cc20a5a0822877e86a43e9a0affb503 (diff)
QMetaType: disable conversion from smart pointer<const QObject>
QMetaType can register a converter from a smart pointer class to QObject *. The code tries to do so even if the smart pointer is actually holding a pointer to a _const_ QObject (e.g. shared_ptr<const QObject>), causing a compile error: ../src/qt5/qtbase/build/include/QtCore/../../../src/corelib/kernel/qmetatype.h:1208:32: error: invalid conversion from ‘const QObject*’ to ‘QObject*’ [-fpermissive] 1208 | return p.operator->(); | ~~~~~~~~~~~~^~ | | | const QObject* Disable the conversion if indeed the source is const qualified. Change-Id: I9e9bc5992f74131e5cfd6ece9b83d4f26d370e92 Fixes: QTBUG-103741 Pick-to: 6.2 6.3 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/corelib/kernel/qobject/tst_qobject.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp
index 2e0895dbb4..f765440e71 100644
--- a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp
+++ b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp
@@ -8224,5 +8224,22 @@ void tst_QObject::emitToDestroyedClass()
static_assert(QtPrivate::HasQ_OBJECT_Macro<tst_QObject>::Value);
static_assert(!QtPrivate::HasQ_OBJECT_Macro<SiblingDeleter>::Value);
+Q_DECLARE_SMART_POINTER_METATYPE(std::shared_ptr)
+Q_DECLARE_SMART_POINTER_METATYPE(std::unique_ptr)
+
+
+// QTBUG-103741: OK to use smart pointers to const QObject in signals/slots
+class SenderWithSharedPointerConstQObject : public QObject
+{
+ Q_OBJECT
+
+signals:
+ void aSignal1(const QSharedPointer<const QObject> &);
+ void aSignal2(const QWeakPointer<const QObject> &);
+ void aSignal3(const QPointer<const QObject> &);
+ void aSignal4(const std::shared_ptr<const QObject> &);
+ void aSignal5(const std::unique_ptr<const QObject> &);
+};
+
QTEST_MAIN(tst_QObject)
#include "tst_qobject.moc"