Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Libexif encoding problem

Libexif encoding problem

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 1.0k 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 6 Oct 2017, 08:22 last edited by samdol 10 Jun 2017, 08:23
    #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?

    J 1 Reply Last reply 6 Oct 2017, 08:46
    0
    • S samdol
      6 Oct 2017, 08:22

      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?

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 6 Oct 2017, 08:46 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 7 Oct 2017, 02:56
      1
      • J jsulm
        6 Oct 2017, 08:46

        @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 7 Oct 2017, 02:56 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?

        J 1 Reply Last reply 9 Oct 2017, 04:14
        0
        • S samdol
          7 Oct 2017, 02:56

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

          J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 9 Oct 2017, 04:14 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

          1/4

          6 Oct 2017, 08:22

          • Login

          • Login or register to search.
          1 out of 4
          • First post
            1/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved