From 8523b68b510c09464d4c99f9d8870cc8290389c2 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Fri, 15 Jul 2022 16:01:02 +0200 Subject: [PATCH] Undeprecate QAction::setMenu(QMenu *) We deprecated QAction::setMenu(QMenu *) in Qt 6.0 because QAction needed to become part of QtGui, and QMenu is a QtWidgets class. To keep existing code working, we added a private API operating on QObject *, and a template overload of setMenu, which allows callers to pass in and get the object as a QMenu without any change to their code. The implementation relies on a virtual function in QApplicationPrivate. This solution might be as good as it gets. Making QAction operate only on QObject* in the public API breaks exiting widget code, and it is unlikely that we will come up with a QMenu abstraction that unifies widgets and Quick UIs without breaking code either. So, undeprecate the existing solution. If we come up with something better, we can still deprecate it again in time for removing it in Qt 7. Change-Id: I1982b61feb1b1af99f4647e892c5fd74340d9c77 Reviewed-by: Volker Hilsheimer Reviewed-by: Ivan Solovev Reviewed-by: Axel Spoerl Reviewed-by: Shawn Rutledge (cherry picked from commit 8fed0a6aa66bf2a78d7e00b60b1ff27979873b86) Reviewed-by: Qt Cherry-pick Bot --- src/gui/kernel/qaction.cpp | 4 +--- src/gui/kernel/qaction.h | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/gui/kernel/qaction.cpp b/src/gui/kernel/qaction.cpp index 8ee6a06ad81..98cbc9c3d59 100644 --- a/src/gui/kernel/qaction.cpp +++ b/src/gui/kernel/qaction.cpp @@ -1191,14 +1191,13 @@ QAction::MenuRole QAction::menuRole() const /*! \fn QMenu *QAction::menu() const - \deprecated Use QMenu::menuInAction instead. Returns the menu contained by this action. In widget applications, actions that contain menus can be used to create menu items with submenus, or inserted into toolbars to create buttons with popup menus. - \sa QMenu::addAction() + \sa QMenu::addAction(), QMenu::menuInAction() */ QObject* QAction::menuObject() const { @@ -1208,7 +1207,6 @@ QObject* QAction::menuObject() const /*! \fn void QAction::setMenu(QMenu *menu) - \deprecated Sets the menu contained by this action to the specified \a menu. */ diff --git a/src/gui/kernel/qaction.h b/src/gui/kernel/qaction.h index 54cfb8a50be..cc854666144 100644 --- a/src/gui/kernel/qaction.h +++ b/src/gui/kernel/qaction.h @@ -20,10 +20,10 @@ QT_BEGIN_NAMESPACE class QActionEvent; class QActionGroup; class QActionPrivate; +class QMenu; #if QT_DEPRECATED_SINCE(6,0) class QWidget; class QGraphicsWidget; -class QMenu; #endif class Q_GUI_EXPORT QAction : public QObject @@ -175,7 +175,6 @@ public: void setMenuRole(MenuRole menuRole); MenuRole menuRole() const; -#if QT_DEPRECATED_SINCE(6,0) #ifdef Q_CLANG_QDOC QMenu *menu() const; void setMenu(QMenu *menu); @@ -190,7 +189,6 @@ public: { setMenuObject(m); } -#endif #endif void setIconVisibleInMenu(bool visible);