Skip to content

Commit 192bf30

Browse files
committed
use a helper class object to make sure locale gets reset properly
1 parent b3dfe9a commit 192bf30

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

QtPMbrowser/pmbrowserwindow.cpp

+16-6
Original file line numberDiff line numberDiff line change
@@ -793,17 +793,30 @@ void PMbrowserWindow::on_actionExport_All_as_IBW_triggered()
793793
}
794794
}
795795

796+
class locale_manager {
797+
std::locale old_locale{};
798+
public:
799+
void setLocale(const char* name){
800+
old_locale = std::locale::global(std::locale(name));
801+
}
802+
~locale_manager() {
803+
std::locale::global(old_locale);
804+
}
805+
};
806+
796807
void PMbrowserWindow::on_actionExport_Metadata_as_Table_triggered()
797808
{
798809
if (!assertDatFileOpen()) {
799810
return;
800811
}
801812
DlgExportMetadata dlg(this);
802813
if (dlg.exec()) {
803-
std::locale old_locale;
814+
locale_manager lm;
804815
if (dlg.useSystemLocale()) {
805-
std::locale new_locale(""); // system default locale
806-
old_locale = std::locale::global(new_locale);
816+
lm.setLocale(""); // set default locale
817+
}
818+
else {
819+
lm.setLocale("C");
807820
}
808821
auto selected = dlg.getSelection();
809822
if (selected < 0)
@@ -836,9 +849,6 @@ void PMbrowserWindow::on_actionExport_Metadata_as_Table_triggered()
836849
}
837850
}
838851
}
839-
if (dlg.useSystemLocale()) {
840-
std::locale::global(old_locale);
841-
}
842852
}
843853
}
844854

0 commit comments

Comments
 (0)