Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read exif metadata of images in Qt

Tags:

qt

exif

In my Qt app I want to read exif data of images. QImage or QPixmap don't seem to provide such hooks.

Is there any API in Qt that allows reading exif without using external libraries like libexif?

EDIT: This is a duplicate of this

like image 434
S B Avatar asked Oct 26 '25 11:10

S B


1 Answers

For me, the best choice was easyexif by Mayank Lahiri. You only need to add two files exif.cpp and exif.h to your project.

int main(int argc, char *argv[])
{
    for (int i=1; i<argc; ++i){
        QFile file(argv[i]);
        if (file.open(QIODevice::ReadOnly)){
            QByteArray data = file.readAll();
            easyexif::EXIFInfo info;
            if (int code = info.parseFrom((unsigned char *)data.data(), data.size())){
                qDebug() << "Error parsing EXIF: code " << code;
                continue;
            }
            qDebug() << "Camera model         : " << info.Model.c_str();
            qDebug() << "Original date/time   : " << info.DateTimeOriginal.c_str();
        } else
            qDebug() << "Can't open file:" << argv[i];           
    }

    return 0;
}
like image 154
olned64 Avatar answered Oct 29 '25 08:10

olned64