@@ -1414,16 +1414,20 @@ void MainWindow::exportModelToOMNotebook(LibraryTreeItem *pLibraryTreeItem)
14141414 mpProgressBar->setValue (value++);
14151415 // create a file object and write the xml in it.
14161416 QFile omnotebookFile (omnotebookFileName);
1417- omnotebookFile.open (QIODevice::WriteOnly);
1418- QTextStream textStream (&omnotebookFile);
1417+ if ( omnotebookFile.open (QIODevice::WriteOnly)) {
1418+ QTextStream textStream (&omnotebookFile);
14191419#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
1420- textStream.setEncoding (QStringConverter::Utf8);
1420+ textStream.setEncoding (QStringConverter::Utf8);
14211421#else
1422- textStream.setCodec (Helper::utf8.toUtf8 ().constData ());
1422+ textStream.setCodec (Helper::utf8.toUtf8 ().constData ());
14231423#endif
1424- textStream.setGenerateByteOrderMark (false );
1425- textStream << xmlDocument.toString ();
1426- omnotebookFile.close ();
1424+ textStream.setGenerateByteOrderMark (false );
1425+ textStream << xmlDocument.toString ();
1426+ omnotebookFile.close ();
1427+ } else {
1428+ QString msg = tr (" Unable to open %1" ).arg (omnotebookFileName);
1429+ MessagesWidget::instance ()->addGUIMessage (MessageItem (MessageItem::Modelica, msg, Helper::scriptingKind, Helper::errorLevel));
1430+ }
14271431 mpProgressBar->setValue (value++);
14281432 // hide the progressbar and clear the message in status bar
14291433 mpStatusBar->clearMessage ();
0 commit comments