What is the bug or the crash?
when a plugin menu is empty after using iface.removePluginMenu the menu is removed from the plugin menu but it is not deleted and stays hidden and alive until the program is closed. meaning that if a plugin is unloaded and reloaded multiple time every time accumulates a new orphan menu.
same goes for removePluginDatabaseMenu(), removePluginMenu(), removePluginMeshMenu(), removePluginRasterMenu(), removePluginVectorMenu(), removePluginWebMenu()
Steps to reproduce the issue
I ran this code in the console:
from qgis.PyQt.QtWidgets import QAction, QMenu
from qgis.PyQt.QtCore import QCoreApplication, QEvent
menu_name = "&Repro Menu"
def dump():
menus = [
menu for menu in iface.mainWindow().findChildren(QMenu)
if menu.title() == menu_name
]
print(f"found {len(menus)} menu(s)")
for index, menu in enumerate(menus, 1):
print(index, menu, "actions =", [action.text() for action in menu.actions()])
print("before:")
dump()
action = QAction("Temporary Action", iface.mainWindow())
action2 = QAction("Temporary Action2", iface.mainWindow())
iface.addPluginToMenu(menu_name, action)
iface.addPluginToMenu(menu_name, action2)
print("\nafter add:")
dump()
iface.removePluginMenu(menu_name, action)
iface.removePluginMenu(menu_name, action2)
action.deleteLater()
QCoreApplication.sendPostedEvents(None, QEvent.Type.DeferredDelete)
QCoreApplication.processEvents()
print("\nafter remove:")
dump()
every time this is run there is another lonely QMenu with the same name.
output after running a few times:
before:
found 3 menu(s)
1 <PyQt5.QtWidgets.QMenu object at 0x000002A106B62F00> actions = []
2 <PyQt5.QtWidgets.QMenu object at 0x000002A106B62F90> actions = []
3 <PyQt5.QtWidgets.QMenu object at 0x000002A106B63020> actions = []
after add:
found 4 menu(s)
1 <PyQt5.QtWidgets.QMenu object at 0x000002A106B62D50> actions = []
2 <PyQt5.QtWidgets.QMenu object at 0x000002A106B62DE0> actions = []
3 <PyQt5.QtWidgets.QMenu object at 0x000002A106B62E70> actions = []
4 <PyQt5.QtWidgets.QMenu object at 0x000002A106B639B0> actions = ['Temporary Action', 'Temporary Action2']
after remove:
found 4 menu(s)
1 <PyQt5.QtWidgets.QMenu object at 0x000002A106B62B10> actions = []
2 <PyQt5.QtWidgets.QMenu object at 0x000002A106B62BA0> actions = []
3 <PyQt5.QtWidgets.QMenu object at 0x000002A106B62C30> actions = []
4 <PyQt5.QtWidgets.QMenu object at 0x000002A106B62CC0> actions = []
Versions
| QGIS version | 3.44.10-Solothurn |
| QGIS code revision | 565fe70b |
| |
| Libraries |
| Qt version | 5.15.13 |
| Python version | 3.12.13 |
| GDAL version | 3.12.4 — Chicoutimi |
| PROJ version | 9.8.1 |
| EPSG Registry database version | v12.029 (2025-10-02) |
| GEOS version | 3.14.1-CAPI-1.20.5 |
| SQLite version | 3.53.0 |
| PDAL version | 2.10.0 |
| PostgreSQL client version | 17.3 |
| SpatiaLite version | 5.1.0 |
| QWT version | 6.3.0 |
| QScintilla2 version | 2.14.1 |
| OS version | Windows 11 Version 2009 |
| |
| Active Python plugins |
| attributeshortcut | 1.1.1 |
| autoSaver | 2.9 |
| plugin_reloader | 0.22 |
| qgis_mcp_plugin | 1.0 |
| SelectionFilter | 2.0 |
| processing | 2.12.99 |
| QGIS version | 4.0.2-Norrköping |
| QGIS code revision | bb929340 |
| |
| Libraries |
| Qt version | 6.11.0 |
| Python version | 3.12.13 |
| GDAL version | 3.12.4 — Chicoutimi |
| PROJ version | 9.8.1 |
| EPSG Registry database version | v12.029 (2025-10-02) |
| GEOS version | 3.14.1-CAPI-1.20.5 |
| SFCGAL version | 2.2.0 |
| GeographicLib version | 2.7.0 |
| SQLite version | 3.53.0 |
| PDAL version | 2.10.0 |
| PostgreSQL client version | 17.3 |
| SpatiaLite version | 5.1.0 |
| QWT version | 6.3.0 |
| QScintilla2 version | 2.14.1 |
| OS version | Windows 11 Version 25H2 |
| |
| Active Python plugins |
| MetaSearch | 0.3.6 |
| db_manager | 0.1.20 |
| grassprovider | 2.12.99 |
| plugin_reloader | 0.22 |
| processing | 2.12.99 |
Supported QGIS version
New profile
No Duplicate of the Issue
Additional context
No response
What is the bug or the crash?
when a plugin menu is empty after using
iface.removePluginMenuthe menu is removed from the plugin menu but it is not deleted and stays hidden and alive until the program is closed. meaning that if a plugin is unloaded and reloaded multiple time every time accumulates a new orphan menu.same goes for removePluginDatabaseMenu(), removePluginMenu(), removePluginMeshMenu(), removePluginRasterMenu(), removePluginVectorMenu(), removePluginWebMenu()
Steps to reproduce the issue
I ran this code in the console:
every time this is run there is another lonely QMenu with the same name.
output after running a few times:
Versions
Supported QGIS version
New profile
No Duplicate of the Issue
Additional context
No response