Show and handle load and save errors
This commit is contained in:
parent
9e6b957f92
commit
20901898a8
2 changed files with 21 additions and 4 deletions
|
@ -46,7 +46,7 @@ void DataModel::write(const QString &filename) const
|
||||||
QFile outFile(filename);
|
QFile outFile(filename);
|
||||||
if (!outFile.open(QIODevice::WriteOnly))
|
if (!outFile.open(QIODevice::WriteOnly))
|
||||||
{
|
{
|
||||||
return;
|
throw std::runtime_error("open failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
dataModel.SerializeToFileDescriptor(outFile.handle());
|
dataModel.SerializeToFileDescriptor(outFile.handle());
|
||||||
|
@ -57,7 +57,7 @@ void DataModel::read(const QString &filename)
|
||||||
QFile inFile(filename);
|
QFile inFile(filename);
|
||||||
if (!inFile.open(QIODevice::ReadOnly))
|
if (!inFile.open(QIODevice::ReadOnly))
|
||||||
{
|
{
|
||||||
return;
|
throw std::runtime_error("open failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
ESGRAF48::DataModel dataModel;
|
ESGRAF48::DataModel dataModel;
|
||||||
|
|
|
@ -85,8 +85,16 @@ void MainWindow::openFile()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
openFile(filename);
|
openFile(filename);
|
||||||
}
|
}
|
||||||
|
catch (std::exception &e)
|
||||||
|
{
|
||||||
|
QString errorMessage = QString("Error loading \"") + filename + "\": " + e.what();
|
||||||
|
QMessageBox::critical(this, "Error", errorMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::openFile(const QString &filename)
|
void MainWindow::openFile(const QString &filename)
|
||||||
{
|
{
|
||||||
|
@ -194,8 +202,17 @@ void MainWindow::closeEvent(QCloseEvent *event)
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::saveFile(const QString &filename)
|
void MainWindow::saveFile(const QString &filename)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
m_dataModel.write(filename);
|
m_dataModel.write(filename);
|
||||||
|
}
|
||||||
|
catch (std::exception &e)
|
||||||
|
{
|
||||||
|
QString errorMessage = QString("Error saving \"") + filename + "\": " + e.what();
|
||||||
|
QMessageBox::critical(this, "Error", errorMessage);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
qDebug() << "Wrote" << filename;
|
qDebug() << "Wrote" << filename;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue