From 07f75f72128f90417b087a8262f46e06a9b86d35 Mon Sep 17 00:00:00 2001 From: dismine Date: Fri, 30 May 2014 17:31:48 +0300 Subject: [PATCH] Catch std::bad_alloc exception. --HG-- branch : develop --- src/app/mainwindow.cpp | 19 +++++++++++++++++++ src/app/xml/vpattern.cpp | 6 ++++++ 2 files changed, 25 insertions(+) diff --git a/src/app/mainwindow.cpp b/src/app/mainwindow.cpp index a51f09f18..b7e24a78b 100644 --- a/src/app/mainwindow.cpp +++ b/src/app/mainwindow.cpp @@ -1888,6 +1888,25 @@ void MainWindow::LoadPattern(const QString &fileName) Clear(); return; } + catch (const std::bad_alloc &) + { +#ifndef QT_NO_CURSOR + QApplication::restoreOverrideCursor(); +#endif + QMessageBox msgBox; + msgBox.setWindowTitle(tr("Error!")); + msgBox.setText(tr("Error parsing file.")); + msgBox.setInformativeText("std::bad_alloc"); + msgBox.setStandardButtons(QMessageBox::Ok); + msgBox.setDefaultButton(QMessageBox::Ok); + msgBox.setIcon(QMessageBox::Warning); + msgBox.exec(); +#ifndef QT_NO_CURSOR + QApplication::setOverrideCursor(Qt::WaitCursor); +#endif + Clear(); + return; + } connect(comboBoxDraws, static_cast(&QComboBox::currentIndexChanged), this, &MainWindow::currentDrawChanged); QString nameDraw = doc->GetNameActivDraw(); diff --git a/src/app/xml/vpattern.cpp b/src/app/xml/vpattern.cpp index 0594b0563..67bd9edc1 100644 --- a/src/app/xml/vpattern.cpp +++ b/src/app/xml/vpattern.cpp @@ -601,6 +601,9 @@ void VPattern::FullUpdateTree() catch (const std::bad_alloc &) { delete scene; +#ifndef QT_NO_CURSOR + QApplication::restoreOverrideCursor(); +#endif QMessageBox msgBox; msgBox.setWindowTitle(tr("Error!")); msgBox.setText(tr("Error parsing file.")); @@ -609,6 +612,9 @@ void VPattern::FullUpdateTree() msgBox.setDefaultButton(QMessageBox::Ok); msgBox.setIcon(QMessageBox::Warning); msgBox.exec(); +#ifndef QT_NO_CURSOR + QApplication::setOverrideCursor(Qt::WaitCursor); +#endif emit ClearMainWindow(); return; }