QShortcut::parentWidget(): Add QT_DEPRECATED_VERSION_X_6_0

And fix the usage that raised a deprecation warning.

As a drive-by: fix the deprecation declaration of QShortcut::id() to
use QT_DEPRECATED_VERSION_6_0 instead of pure Q_DECL_DEPRECATED.

Task-number: QTBUG-104857
Pick-to: 6.4 6.3 6.2
Change-Id: I5710127864909ce9352c7428e6aabbc89981b8f2
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
This commit is contained in:
Ivan Solovev 2022-07-11 14:51:06 +02:00
parent 68ea9c0227
commit fc172e3093
2 changed files with 3 additions and 2 deletions

View File

@ -170,7 +170,7 @@ public:
bool autoRepeat() const;
#if QT_DEPRECATED_SINCE(6,0)
Q_DECL_DEPRECATED int id() const;
QT_DEPRECATED_VERSION_6_0 int id() const;
#endif
void setWhatsThis(const QString &text);
@ -181,6 +181,7 @@ public:
QWidget *parentWidget() const;
#else
template<typename T = QWidget*>
QT_DEPRECATED_VERSION_X_6_0("Use parent() and qobject_cast instead")
inline T parentWidget() const
{ return static_cast<T>(QObject::parent()); }
#endif

View File

@ -81,7 +81,7 @@ bool qWidgetShortcutContextMatcher(QObject *object, Qt::ShortcutContext context)
auto w = qobject_cast<QWidget *>(object);
if (!w) {
if (auto s = qobject_cast<QShortcut *>(object))
w = s->parentWidget();
w = qobject_cast<QWidget *>(s->parent());
}
if (!w) {