From e312545204ba82133921376d1493e1eb0be8c31d Mon Sep 17 00:00:00 2001 From: YiFang Xiao Date: Wed, 24 Jan 2024 22:55:34 +0800 Subject: [PATCH] fix: possible crash on macos --- src/ui/stylescombobox.cc | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/ui/stylescombobox.cc b/src/ui/stylescombobox.cc index f14d06a4e..ddfb1342c 100644 --- a/src/ui/stylescombobox.cc +++ b/src/ui/stylescombobox.cc @@ -8,7 +8,6 @@ StylesComboBox::StylesComboBox( QWidget * parent ): QComboBox( parent ) { fill(); - setVisible( count() > 1 ); } void StylesComboBox::fill() @@ -19,26 +18,25 @@ void StylesComboBox::fill() if ( !stylesDir.isEmpty() ) { QDir dir( stylesDir ); QStringList styles = dir.entryList( QDir::Dirs | QDir::NoDotAndDotDot, QDir::LocaleAware ); - addItems( styles ); + if ( !styles.isEmpty() ) { + addItems( styles ); + } } + + setVisible( count() > 1 ); } void StylesComboBox::setCurrentStyle( QString const & style ) { - int nom = 0; - if ( !style.isEmpty() ) { - for ( int i = 1; i < count(); i++ ) - if ( style.compare( itemText( i ) ) == 0 ) { - nom = i; - break; - } + int nom = findText( style ); + if ( nom > -1 ) { + setCurrentIndex( nom ); } - setCurrentIndex( nom ); } QString StylesComboBox::getCurrentStyle() const { if ( currentIndex() == 0 ) - return QString(); + return {}; return itemText( currentIndex() ); }