Skip to content

Commit 8545cb8

Browse files
committed
prevent exception during metadata export from reaching Qt event loop, fixes #46
1 parent 192bf30 commit 8545cb8

File tree

1 file changed

+34
-34
lines changed

1 file changed

+34
-34
lines changed

QtPMbrowser/pmbrowserwindow.cpp

+34-34
Original file line numberDiff line numberDiff line change
@@ -811,44 +811,44 @@ void PMbrowserWindow::on_actionExport_Metadata_as_Table_triggered()
811811
}
812812
DlgExportMetadata dlg(this);
813813
if (dlg.exec()) {
814-
locale_manager lm;
815-
if (dlg.useSystemLocale()) {
816-
lm.setLocale(""); // set default locale
817-
}
818-
else {
819-
lm.setLocale("C");
820-
}
821-
auto selected = dlg.getSelection();
822-
if (selected < 0)
823-
{
824-
selected = hkTreeNode::LevelTrace;
825-
}
826-
else {
827-
++selected; // first item in box is level 1
828-
}
829-
if (dlg.doCopy()) {
830-
std::ostringstream s;
831-
this->formatStimMetadataAsTableExport(s, selected);
832-
QGuiApplication::clipboard()->setText(s.str().c_str());
833-
}
834-
else {
835-
auto export_file_name = QFileDialog::getSaveFileName(this, "Export Metadata as TXT",
836-
lastexportpath, "tab separated file (*.txt *.csv)");
837-
if (export_file_name.length() > 0) {
838-
std::ofstream export_file(export_file_name.toStdString());
839-
if (!export_file) {
840-
QMessageBox::warning(this, "Error",
841-
QString("Cannot open file '%1'\nfor saving").arg(export_file_name));
842-
return;
843-
}
844-
try {
814+
try {
815+
locale_manager lm;
816+
if (dlg.useSystemLocale()) {
817+
lm.setLocale(""); // set default locale
818+
}
819+
else {
820+
lm.setLocale("C");
821+
}
822+
auto selected = dlg.getSelection();
823+
if (selected < 0)
824+
{
825+
selected = hkTreeNode::LevelTrace;
826+
}
827+
else {
828+
++selected; // first item in box is level 1
829+
}
830+
if (dlg.doCopy()) {
831+
std::ostringstream s;
832+
this->formatStimMetadataAsTableExport(s, selected);
833+
QGuiApplication::clipboard()->setText(s.str().c_str());
834+
}
835+
else {
836+
auto export_file_name = QFileDialog::getSaveFileName(this, "Export Metadata as TXT",
837+
lastexportpath, "tab separated file (*.txt *.csv)");
838+
if (export_file_name.length() > 0) {
839+
std::ofstream export_file(export_file_name.toStdString());
840+
if (!export_file) {
841+
QMessageBox::warning(this, "Error",
842+
QString("Cannot open file '%1'\nfor saving").arg(export_file_name));
843+
return;
844+
}
845845
this->formatStimMetadataAsTableExport(export_file, selected);
846846
}
847-
catch (const std::exception& e) {
848-
QMessageBox::warning(this, "Error while exporting", e.what());
849-
}
850847
}
851848
}
849+
catch (const std::exception& e) {
850+
QMessageBox::warning(this, "Error while exporting", e.what());
851+
}
852852
}
853853
}
854854

0 commit comments

Comments
 (0)