Libexif encoding problem

  • Hi,

    I am trying to get EXIF info of jpg file using libexif library.
    To do that, I need to get ExifData* by
    QString filePath("C:/mfile");
    ExifData *exifData = exif_data_new_from_file(filePath.toLatin1());
    If filePath is in pure english charactors, there is no problem, I could get
    exifData correctly. But if filePath contains chinese charactors, this does not
    work well, it returns null exifData.
    I tried the followings, but none of them worked, they all return null exifData.
    exifData = exif_data_new_from_file(filePath.toLatin1().data());
    exifData = exif_data_new_from_file(filePath.toLocal8Bit().data());
    exifData = exif_data_new_from_file(filePath.toLocal8Bit().constData());
    exifData = exif_data_new_from_file(QFile::encodeName(filePath).constData());
    exifData = exif_data_new_from_file(filePath.toStdString().c_str());

    The prototype of the function in use is
    ExifData* exif_data_new_from_file(const char *path)

    Can I have some hint how I can get exifData of file which contains chinese charactors?

  • Moderators

    @samdol First thing to check would be whether LibExif supports anything else than ASCII for paths. But this is not related to Qt.

  • @jsulm
    When I tried the following code in Linux Qt4.8.x, I could get the right result, exif_data_new_from_file return non-zero ed.

        QString filename("/home/myhome/学校.jpg");
        QByteArray filenameBA = filename.toUtf8();
         const char *filename_char = filenameBA.constData();
        ed = exif_data_new_from_file(filename_char);

    So it seems LibExif itself supports Chinese charactors too. Unfortunatly, Qt5 does not support TextCodec::setCodecForCStrings() method anymore, and my target platform is Windows. As far as I know, unlike Linux, Windows default codec is not UTF-8. How can I fix it?

  • Moderators

    @samdol How do you get the file names in your app?

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.