From fdfdffc9b0469f674c2a152308f30c203eb55cc3 Mon Sep 17 00:00:00 2001 From: Austen Date: Fri, 20 Jun 2014 14:35:39 -0400 Subject: [PATCH] Exiv2 error handling implemented. Now it doesn't crash when there's a gif --- picture.cpp | 22 +++++++++++++++------- picture.ui | 2 +- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/picture.cpp b/picture.cpp index 2bf85b6..e32f443 100644 --- a/picture.cpp +++ b/picture.cpp @@ -3,6 +3,7 @@ #include #include #include +#include Picture::Picture(QWidget *parent) : QMainWindow(parent), ui(new Ui::Picture){ @@ -31,7 +32,6 @@ void Picture::dropEvent(QDropEvent *event){ //qDebug() << "Dropped file:" << fileName; } } - void Picture::changeDirectory(){ QString path=QFileDialog::getExistingDirectory(this,tr("Directory"),directory.path()); if(path.isNull()==false){ @@ -69,12 +69,20 @@ void Picture::on_erase_clicked(){ QImageReader reader(str); if(!reader.format().isEmpty()){ QString fullPath=str; - Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(fullPath.toStdString()); - assert (image.get() != 0); - image->readMetadata(); - Exiv2::ExifData &exifData = image->exifData(); - exifData["Exif.Photo.UserComment"] = "charset=Ascii An ASCII Exif comment added with Exiv2"; - image->writeMetadata(); + try{ + Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(fullPath.toStdString()); + assert (image.get() != 0); + image->readMetadata(); + Exiv2::ExifData &exifData = image->exifData(); + exifData["Exif.Photo.UserComment"] = "charset=Ascii An ASCII Exif comment added with Exiv2"; + image->writeMetadata(); + }catch(Exiv2::AnyError& e){ + QMessageBox msgBox; + msgBox.setInformativeText("The program could not process the file: "+fullPath); + msgBox.setStandardButtons(QMessageBox::Ok); + msgBox.setDefaultButton(QMessageBox::Ok); + int ret=msgBox.exec(); + } }else{ if(!ignored){ ignored=true; diff --git a/picture.ui b/picture.ui index 25dae5b..5ad7038 100644 --- a/picture.ui +++ b/picture.ui @@ -41,7 +41,7 @@ - Change Directory + Open Directory