Browse Source

Error handling if file does not exist/is not readable

Ivo Wolf 13 years ago
parent
commit
06b9f951e2
1 changed files with 20 additions and 7 deletions
  1. 20 7
      Plugins/org.commontk.dah.exampleapp/ctkExampleDicomAppLogic.cpp

+ 20 - 7
Plugins/org.commontk.dah.exampleapp/ctkExampleDicomAppLogic.cpp

@@ -245,17 +245,30 @@ void ctkExampleDicomAppLogic::onLoadDataClicked()
     if(filename.startsWith("file:/",Qt::CaseInsensitive))
       filename=filename.remove(0,8);
     qDebug()<<filename;
-    DicomImage dcmtkImage(filename.toLatin1().data());
-    ctkDICOMImage ctkImage(&dcmtkImage);
-
-    QPixmap pixmap = QPixmap::fromImage(ctkImage.frame(0),Qt::AvoidDither);
-    if (pixmap.isNull())
+    if(QFileInfo(filename).exists())
     {
-      qCritical() << "Failed to convert QImage to QPixmap" ;
+      try {
+        DicomImage dcmtkImage(filename.toLatin1().data());
+        ctkDICOMImage ctkImage(&dcmtkImage);
+
+        QPixmap pixmap = QPixmap::fromImage(ctkImage.frame(0),Qt::AvoidDither);
+        if (pixmap.isNull())
+        {
+          qCritical() << "Failed to convert QImage to QPixmap" ;
+        }
+        else
+        {
+          ui.PlaceHolderForImage->setPixmap(pixmap);
+        }
+      }
+      catch(...)
+      {
+        qCritical() << "Caught exception while trying to load file" << filename;
+      }
     }
     else
     {
-      ui.PlaceHolderForImage->setPixmap(pixmap);
+      qCritical() << "File does not exist: " << filename;
     }
   }
   ui.ReceivedDataInformation->setText(s);