[vlc-devel] [PATCH] qt: open_panels: prevent the dialog customization from crashing
Alexandre Janniaux
ajanni at videolabs.io
Thu Jul 25 01:23:22 CEST 2019
Check that the widgets extracted from the Qt widgets tree are valid
before using them, otherwise operator[] would crash on access.
More work would be needed to use a safer and more sustainable way to
customize the dialog box. In the mean time, this prevent the UI from
crashing with the new UI.
It was reported on platform like Suze Leap 15.1 when opening a disk.
---
modules/gui/qt/components/open_panels.cpp | 35 ++++++++++++++++-------
1 file changed, 24 insertions(+), 11 deletions(-)
diff --git a/modules/gui/qt/components/open_panels.cpp b/modules/gui/qt/components/open_panels.cpp
index b92ec91242..8308250c25 100644
--- a/modules/gui/qt/components/open_panels.cpp
+++ b/modules/gui/qt/components/open_panels.cpp
@@ -144,21 +144,35 @@ inline void FileOpenPanel::BuildOldPanel()
dialogBox->setToolTip( qtr( "Select one or multiple files" ) );
dialogBox->setMinimumHeight( 250 );
+#warning Qt open_panels should use a more sustainable way to customize FileDialogBox
+ /* Ugly hacks to get the good Widget */
// But hide the two OK/Cancel buttons. Enable them for debug.
- QDialogButtonBox *fileDialogAcceptBox =
- dialogBox->findChildren<QDialogButtonBox*>()[0];
- fileDialogAcceptBox->hide();
+ QList<QDialogButtonBox*> buttons =
+ dialogBox->findChildren<QDialogButtonBox*>();
+ if( !buttons.isEmpty() )
+ {
+ QDialogButtonBox *fileDialogAcceptBox = buttons[0];
+ fileDialogAcceptBox->hide();
+ }
- /* Ugly hacks to get the good Widget */
- //This lineEdit is the normal line in the fileDialog.
- QLineEdit *lineFileEdit = dialogBox->findChildren<QLineEdit*>()[0];
/* Make a list of QLabel inside the QFileDialog to access the good ones */
QList<QLabel *> listLabel = dialogBox->findChildren<QLabel*>();
- /* Hide the FileNames one. Enable it for debug */
- listLabel[1]->setText( qtr( "File names:" ) );
- /* Change the text that was uncool in the usual box */
- listLabel[2]->setText( qtr( "Filter:" ) );
+ if( listLabel.size() > 3 )
+ {
+ /* Hide the FileNames one. Enable it for debug */
+ listLabel[1]->setText( qtr( "File names:" ) );
+ /* Change the text that was uncool in the usual box */
+ listLabel[2]->setText( qtr( "Filter:" ) );
+ }
+
+ //This lineEdit is the normal line in the fileDialog.
+ QList<QLineEdit*> lineEdits = dialogBox->findChildren<QLineEdit*>();
+ if( !lineEdits.isEmpty() )
+ {
+ QLineEdit *lineFileEdit = lineEdits[0];
+ CONNECT( lineFileEdit, textChanged( const QString& ), this, updateMRL() );
+ }
dialogBox->layout()->setMargin( 0 );
dialogBox->layout()->setSizeConstraint( QLayout::SetNoConstraint );
@@ -168,7 +182,6 @@ inline void FileOpenPanel::BuildOldPanel()
// Add the DialogBox to the layout
ui.gridLayout->addWidget( dialogBox, 0, 0, 1, 3 );
- CONNECT( lineFileEdit, textChanged( const QString& ), this, updateMRL() );
dialogBox->installEventFilter( this );
}
--
2.22.0
More information about the vlc-devel
mailing list