From da2fd6a9038b1130a2ae411546216d8874ffa4f7 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Mon, 6 Sep 2021 08:54:42 -0700 Subject: [PATCH] Q_DECLARE_INTERFACE: add missing const to const qobject_cast [ChangeLog][Potantially Source-Incompatible Changes] The macro Q_DECLARE_INTERFACE used to cast away the constness of the QObject parameter. That is now fixed in this release, but may cause failure to build source code that depended on this incorrect behavior. If fixing the const correctness in your code is not an option, insert an explicit const_cast of the object prior to the qobject_cast call. Change-Id: Ie72b0dd0fbe84d2caae0fffd16a246a36f0c088f Reviewed-by: Rui Oliveira Reviewed-by: Qt CI Bot Reviewed-by: Volker Hilsheimer --- src/corelib/kernel/qobject.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/corelib/kernel/qobject.h b/src/corelib/kernel/qobject.h index c2fc2910f0..f1e0662461 100644 --- a/src/corelib/kernel/qobject.h +++ b/src/corelib/kernel/qobject.h @@ -501,7 +501,7 @@ inline QBindingStorage *qGetBindingStorage(QObject *o) { return IId; } \ template <> inline IFace *qobject_cast(QObject *object) \ { return reinterpret_cast((object ? object->qt_metacast(IId) : nullptr)); } \ - template <> inline IFace *qobject_cast(const QObject *object) \ + template <> inline const IFace *qobject_cast(const QObject *object) \ { return reinterpret_cast((object ? const_cast(object)->qt_metacast(IId) : nullptr)); } #endif // Q_MOC_RUN