From aef6e08f6064acf3430a59e7bd6aff214ee1e065 Mon Sep 17 00:00:00 2001 From: ccolin Date: Mon, 4 Jan 2021 17:59:01 +0100 Subject: [PATCH] warn upon json parse error --- src/main_window.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main_window.cc b/src/main_window.cc index ad3a7fe..dbe82a9 100644 --- a/src/main_window.cc +++ b/src/main_window.cc @@ -12,7 +12,6 @@ MainWindow::MainWindow(QWidget *parent) { (void) parent; connect(&glw, &OpenGLWidget::initialized, this, &MainWindow::onOpenGLWidgetInitialized); - // connect(&timer, &QTimer::timeout, this, &MainWindow::step); setCentralWidget(&glw); addToolBar(Qt::TopToolBarArea, &top_tb); open_action = top_tb.addAction("Ouvrir…", [&]() { @@ -59,7 +58,12 @@ void MainWindow::open(const QString &path) { return; } QByteArray data = file.readAll(); - QJsonDocument json_doc = QJsonDocument::fromJson(data); + QJsonParseError error; + QJsonDocument json_doc = QJsonDocument::fromJson(data, &error); + if (error.error != QJsonParseError::NoError) { + qWarning() << "Erreur lors de la lecture du ficher JSON:" << error.errorString(); + return; + } if (dc) delete dc; glw.meshes.clear(); dc = new DroneController(json_doc.object());