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.

Pick-to: 6.4 6.3 6.2
Change-Id: I1982b61feb1b1af99f4647e892c5fd74340d9c77
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
This commit is contained in:
Volker Hilsheimer 2022-07-15 16:01:02 +02:00 committed by Ivan Solovev
parent a18a88b19b
commit 8fed0a6aa6
2 changed files with 2 additions and 6 deletions

View File

@ -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.
*/

View File

@ -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);