[vlc-commits] commit: qt4: Don't create QMenu without parents (Erwan Tulou )
git at videolan.org
git at videolan.org
Tue Apr 6 16:56:06 CEST 2010
vlc | branch: master | Erwan Tulou <erwan10 at videolan.org> | Tue Apr 6 16:40:11 2010 +0200| [8d8bd80666aff8073f1ccd37a41cd1786096b0c3] | committer: Erwan Tulou
qt4: Don't create QMenu without parents
This patch ensures that _all_ menus/actions have got a parent widget that
is guaranteed to be deleted.
This patch
- solves memory leaks for menus and action(children)
- solves a side effect (crash) pointed out
by 193e6eacddb63e8a5bda42395ee79b5b27db6408 where
some vlc objects were no longer properly released for lack
of a clean menus/actions release chain.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=8d8bd80666aff8073f1ccd37a41cd1786096b0c3
---
modules/gui/qt4/components/interface_widgets.cpp | 2 +-
.../gui/qt4/components/playlist/standardpanel.cpp | 2 +-
modules/gui/qt4/dialogs_provider.cpp | 17 ++++++++++---
modules/gui/qt4/dialogs_provider.hpp | 1 +
modules/gui/qt4/main_interface.cpp | 4 +-
modules/gui/qt4/menus.cpp | 24 ++++++++++----------
modules/gui/qt4/menus.hpp | 8 +++---
7 files changed, 34 insertions(+), 24 deletions(-)
diff --git a/modules/gui/qt4/components/interface_widgets.cpp b/modules/gui/qt4/components/interface_widgets.cpp
index ce17b9d..29ce6bd 100644
--- a/modules/gui/qt4/components/interface_widgets.cpp
+++ b/modules/gui/qt4/components/interface_widgets.cpp
@@ -356,7 +356,7 @@ void BackgroundWidget::paintEvent( QPaintEvent *e )
void BackgroundWidget::contextMenuEvent( QContextMenuEvent *event )
{
- QVLCMenu::PopupMenu( p_intf, true );
+ QVLCMenu::PopupMenu( p_intf, true, this );
event->accept();
}
diff --git a/modules/gui/qt4/components/playlist/standardpanel.cpp b/modules/gui/qt4/components/playlist/standardpanel.cpp
index 6dcf065..64b5920 100644
--- a/modules/gui/qt4/components/playlist/standardpanel.cpp
+++ b/modules/gui/qt4/components/playlist/standardpanel.cpp
@@ -174,7 +174,7 @@ void StandardPLPanel::popupPlView( const QPoint &point )
QModelIndexList list = selection->selectedIndexes();
if( !model->popup( index, globalPoint, list ) )
- QVLCMenu::PopupMenu( p_intf, true );
+ QVLCMenu::PopupMenu( p_intf, true, this );
}
void StandardPLPanel::popupSelectColumn( QPoint pos )
diff --git a/modules/gui/qt4/dialogs_provider.cpp b/modules/gui/qt4/dialogs_provider.cpp
index 0c6cfdf..9fb00cd 100644
--- a/modules/gui/qt4/dialogs_provider.cpp
+++ b/modules/gui/qt4/dialogs_provider.cpp
@@ -83,6 +83,13 @@ DialogsProvider::DialogsProvider( intf_thread_t *_p_intf ) :
CONNECT( SDMapper, mapped (QString), this, SDMenuAction( QString ) );
new DialogHandler (p_intf, this );
+
+ /* a root widget intended to be the ancestor of all
+ menus/actions created by the dialog_provider methods.
+ At destruction time, deleting this fake widget ensures
+ all child menus/actions are also deleted
+ */
+ root = new QWidget();
}
DialogsProvider::~DialogsProvider()
@@ -101,6 +108,8 @@ DialogsProvider::~DialogsProvider()
delete menusMapper;
delete menusUpdateMapper;
delete SDMapper;
+
+ delete root;
}
void DialogsProvider::quit()
@@ -147,13 +156,13 @@ void DialogsProvider::customEvent( QEvent *event )
vlmDialog(); break;
#endif
case INTF_DIALOG_POPUPMENU:
- QVLCMenu::PopupMenu( p_intf, (de->i_arg != 0) ); break;
+ QVLCMenu::PopupMenu( p_intf, (de->i_arg != 0), root ); break;
case INTF_DIALOG_AUDIOPOPUPMENU:
- QVLCMenu::AudioPopupMenu( p_intf ); break;
+ QVLCMenu::AudioPopupMenu( p_intf, root ); break;
case INTF_DIALOG_VIDEOPOPUPMENU:
- QVLCMenu::VideoPopupMenu( p_intf ); break;
+ QVLCMenu::VideoPopupMenu( p_intf, root ); break;
case INTF_DIALOG_MISCPOPUPMENU:
- QVLCMenu::MiscPopupMenu( p_intf ); break;
+ QVLCMenu::MiscPopupMenu( p_intf, root ); break;
case INTF_DIALOG_WIZARD:
case INTF_DIALOG_STREAMWIZARD:
openAndStreamingDialogs(); break;
diff --git a/modules/gui/qt4/dialogs_provider.hpp b/modules/gui/qt4/dialogs_provider.hpp
index 8bf708e..60f1dd8 100644
--- a/modules/gui/qt4/dialogs_provider.hpp
+++ b/modules/gui/qt4/dialogs_provider.hpp
@@ -130,6 +130,7 @@ private:
static DialogsProvider *instance;
intf_thread_t *p_intf;
+ QWidget* root;
bool b_isDying;
void openDialog( int );
diff --git a/modules/gui/qt4/main_interface.cpp b/modules/gui/qt4/main_interface.cpp
index 6cba05f..13c4555 100644
--- a/modules/gui/qt4/main_interface.cpp
+++ b/modules/gui/qt4/main_interface.cpp
@@ -526,12 +526,12 @@ inline void MainInterface::restoreStackOldWidget()
void MainInterface::destroyPopupMenu()
{
- QVLCMenu::PopupMenu( p_intf, false );
+ QVLCMenu::PopupMenu( p_intf, false, this );
}
void MainInterface::popupMenu( const QPoint &p )
{
- QVLCMenu::PopupMenu( p_intf, true );
+ QVLCMenu::PopupMenu( p_intf, true, this );
}
void MainInterface::toggleFSC()
diff --git a/modules/gui/qt4/menus.cpp b/modules/gui/qt4/menus.cpp
index b0f4264..5991d01 100644
--- a/modules/gui/qt4/menus.cpp
+++ b/modules/gui/qt4/menus.cpp
@@ -423,9 +423,12 @@ QMenu *QVLCMenu::ViewMenu( intf_thread_t *p_intf, QMenu *current, MainInterface
QAction *action;
QMenu *menu;
+ MainInterface *mi = _mi ? _mi : p_intf->p_sys->p_mi;
+ assert( mi );
+
if( !current )
{
- menu = new QMenu( qtr( "&View" ) );
+ menu = new QMenu( qtr( "&View" ), mi );
}
else
{
@@ -442,9 +445,6 @@ QMenu *QVLCMenu::ViewMenu( intf_thread_t *p_intf, QMenu *current, MainInterface
}
}
- MainInterface *mi = _mi ? _mi : p_intf->p_sys->p_mi;
- assert( mi );
-
menu->addAction( QIcon( ":/menu/playlist_menu" ),
qtr( "Play&list" ), mi,
SLOT( togglePlaylist() ), qtr( "Ctrl+L" ) );
@@ -885,7 +885,7 @@ void QVLCMenu::PopupMenuStaticEntries( QMenu *menu )
}
/* Video Tracks and Subtitles tracks */
-void QVLCMenu::VideoPopupMenu( intf_thread_t *p_intf )
+void QVLCMenu::VideoPopupMenu( intf_thread_t *p_intf, QWidget *parent )
{
POPUP_BOILERPLATE;
if( p_input )
@@ -897,12 +897,12 @@ void QVLCMenu::VideoPopupMenu( intf_thread_t *p_intf )
vlc_object_release( p_vout );
}
}
- QMenu *menu = new QMenu();
+ QMenu *menu = new QMenu( parent );
CREATE_POPUP;
}
/* Audio Tracks */
-void QVLCMenu::AudioPopupMenu( intf_thread_t *p_intf )
+void QVLCMenu::AudioPopupMenu( intf_thread_t *p_intf, QWidget *parent )
{
POPUP_BOILERPLATE;
if( p_input )
@@ -912,12 +912,12 @@ void QVLCMenu::AudioPopupMenu( intf_thread_t *p_intf )
if( p_aout )
vlc_object_release( p_aout );
}
- QMenu *menu = new QMenu();
+ QMenu *menu = new QMenu( parent );
CREATE_POPUP;
}
/* Navigation stuff, and general menus ( open ), used only for skins */
-void QVLCMenu::MiscPopupMenu( intf_thread_t *p_intf )
+void QVLCMenu::MiscPopupMenu( intf_thread_t *p_intf, QWidget *parent )
{
POPUP_BOILERPLATE;
@@ -928,7 +928,7 @@ void QVLCMenu::MiscPopupMenu( intf_thread_t *p_intf )
PUSH_SEPARATOR;
}
- QMenu *menu = new QMenu();
+ QMenu *menu = new QMenu( parent );
Populate( p_intf, menu, varnames, objects );
menu->addSeparator();
@@ -947,7 +947,7 @@ void QVLCMenu::MiscPopupMenu( intf_thread_t *p_intf )
}
/* Main Menu that sticks everything together */
-void QVLCMenu::PopupMenu( intf_thread_t *p_intf, bool show )
+void QVLCMenu::PopupMenu( intf_thread_t *p_intf, bool show, QWidget *parent )
{
/* Delete old popup if there is one */
delete p_intf->p_sys->p_popup_menu;
@@ -959,7 +959,7 @@ void QVLCMenu::PopupMenu( intf_thread_t *p_intf, bool show )
}
/* */
- QMenu *menu = new QMenu();
+ QMenu *menu = new QMenu( parent );
QAction *action;
bool b_isFullscreen = false;
MainInterface *mi = p_intf->p_sys->p_mi;
diff --git a/modules/gui/qt4/menus.hpp b/modules/gui/qt4/menus.hpp
index 4a022ce..1ed4228 100644
--- a/modules/gui/qt4/menus.hpp
+++ b/modules/gui/qt4/menus.hpp
@@ -79,10 +79,10 @@ public:
static void createMenuBar( MainInterface *mi, intf_thread_t * );
/* Popups Menus */
- static void PopupMenu( intf_thread_t *, bool );
- static void AudioPopupMenu( intf_thread_t * );
- static void VideoPopupMenu( intf_thread_t * );
- static void MiscPopupMenu( intf_thread_t * );
+ static void PopupMenu( intf_thread_t *, bool, QWidget * );
+ static void AudioPopupMenu( intf_thread_t *, QWidget * );
+ static void VideoPopupMenu( intf_thread_t *, QWidget * );
+ static void MiscPopupMenu( intf_thread_t *, QWidget * );
/* Systray */
static void updateSystrayMenu( MainInterface *, intf_thread_t *,
More information about the vlc-commits
mailing list