diff --git a/src/corelib/kernel/qobject.h b/src/corelib/kernel/qobject.h index a7b2648e45..824a29a5a4 100644 --- a/src/corelib/kernel/qobject.h +++ b/src/corelib/kernel/qobject.h @@ -384,6 +384,8 @@ bool QObject::setProperty(const char *name, QVariant &&value) template inline T qobject_cast(QObject *object) { + static_assert(std::is_pointer_v, + "qobject_cast requires to cast towards a pointer type"); typedef typename std::remove_cv::type>::type ObjType; static_assert(QtPrivate::HasQ_OBJECT_Macro::Value, "qobject_cast requires the type to have a Q_OBJECT macro"); @@ -393,6 +395,10 @@ inline T qobject_cast(QObject *object) template inline T qobject_cast(const QObject *object) { + static_assert(std::is_pointer_v, + "qobject_cast requires to cast towards a pointer type"); + static_assert(std::is_const_v>, + "qobject_cast cannot cast away constness (use const_cast)"); typedef typename std::remove_cv::type>::type ObjType; static_assert(QtPrivate::HasQ_OBJECT_Macro::Value, "qobject_cast requires the type to have a Q_OBJECT macro");