Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Libexif encoding problem
Qt 6.12 LTS is out! See what's new in the release blog

Libexif encoding problem

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 1.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    samdol
    wrote on last edited by samdol
    #1

    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?

    jsulmJ 1 Reply Last reply
    0
    • S samdol

      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?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

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

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      S 1 Reply Last reply
      1
      • jsulmJ jsulm

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

        S Offline
        S Offline
        samdol
        wrote on last edited by
        #3

        @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?

        jsulmJ 1 Reply Last reply
        0
        • S samdol

          @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?

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

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

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt
          • Unsolved