Add error handling when QImage::load fails.
authorgregor herrmann <gregor@toastfreeware.priv.at>
Thu, 20 Jul 2017 11:05:23 +0000 (13:05 +0200)
committergregor herrmann <gregoa@debian.org>
Thu, 20 Jul 2017 14:33:06 +0000 (16:33 +0200)
qtapp/barcode2cash/mainwindow.cpp

index 0b086599b8d1f9a80199748f52d7997fa36632f3..bd5717e73df8025061d5c7e8a486ab14f732d735 100644 (file)
@@ -119,6 +119,10 @@ void MainWindow::showCaptureError(int, QCameraImageCapture::Error error, QString
 
 void MainWindow::analyze() {
     QImage qimage("test.jpg");
+    if (qimage.isNull()) {
+        ui->labAnalyzeImage->setText("Can't read image");
+        return;
+    }
     qimage = qimage.convertToFormat(QImage::Format_Grayscale8);
     auto zbimage = zbar::Image(qimage.width(), qimage.height(), "GREY", qimage.constBits(), qimage.byteCount());
     auto scanner = zbar::ImageScanner();