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. Avoid dealing with QString::normalized when converting to and from std::string
Forum Updated to NodeBB v4.3 + New Features

Avoid dealing with QString::normalized when converting to and from std::string

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 688 Views 1 Watching
  • 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.
  • J Offline
    J Offline
    J0Nes
    wrote on 29 Oct 2021, 14:24 last edited by
    #1

    Hey,

    I am struggling with a Third Party dependency that heavily relies on std::filesystem to do its thing.
    When working with Qt 5.15.2 I always have to normalize my QStrings before passing them to the library. Apparently Qt uses a different default unicode normalization which is quite annoying.
    Without normalization, Qt and the library detects some unicode characters quite different (e.g. the German character ä) making string comparison fail.

    So what I always have to do:

    QString foo(QString string) {
        std::string stdString = string.normalized(QString::NormalizationForm_KD).toStdString();
        std::string resultingString = _library->bar(stdString);
        return QString::fromStdString(resultingString).normalized(QString::NormalizationForm_KC);
    }
    

    Is there a way to tell Qt to always normalize strings in a certain way?
    Thanks a lot!

    P 1 Reply Last reply 29 Oct 2021, 14:29
    0
    • J J0Nes
      29 Oct 2021, 14:24

      Hey,

      I am struggling with a Third Party dependency that heavily relies on std::filesystem to do its thing.
      When working with Qt 5.15.2 I always have to normalize my QStrings before passing them to the library. Apparently Qt uses a different default unicode normalization which is quite annoying.
      Without normalization, Qt and the library detects some unicode characters quite different (e.g. the German character ä) making string comparison fail.

      So what I always have to do:

      QString foo(QString string) {
          std::string stdString = string.normalized(QString::NormalizationForm_KD).toStdString();
          std::string resultingString = _library->bar(stdString);
          return QString::fromStdString(resultingString).normalized(QString::NormalizationForm_KC);
      }
      

      Is there a way to tell Qt to always normalize strings in a certain way?
      Thanks a lot!

      P Offline
      P Offline
      Pl45m4
      wrote on 29 Oct 2021, 14:29 last edited by
      #2

      @J0Nes said in Avoid dealing with QString::normalized when converting to and from std::string:

      Is there a way to tell Qt to always normalize strings in a certain way?

      Have a look yourself

      • https://doc.qt.io/qt-5/qstring.html#normalized
      • https://doc.qt.io/qt-5/qstring.html#NormalizationForm-enum
      • https://doc.qt.io/qt-5/qchar.html#UnicodeVersion-enum

      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      J 1 Reply Last reply 29 Oct 2021, 14:34
      0
      • P Pl45m4
        29 Oct 2021, 14:29

        @J0Nes said in Avoid dealing with QString::normalized when converting to and from std::string:

        Is there a way to tell Qt to always normalize strings in a certain way?

        Have a look yourself

        • https://doc.qt.io/qt-5/qstring.html#normalized
        • https://doc.qt.io/qt-5/qstring.html#NormalizationForm-enum
        • https://doc.qt.io/qt-5/qchar.html#UnicodeVersion-enum
        J Offline
        J Offline
        J0Nes
        wrote on 29 Oct 2021, 14:34 last edited by
        #3

        @Pl45m4

        sure, that's what I am doing in my quoted code - but I'd love tell Qt to always apply this normalization

        P 1 Reply Last reply 29 Oct 2021, 14:50
        0
        • J J0Nes
          29 Oct 2021, 14:34

          @Pl45m4

          sure, that's what I am doing in my quoted code - but I'd love tell Qt to always apply this normalization

          P Offline
          P Offline
          Pl45m4
          wrote on 29 Oct 2021, 14:50 last edited by
          #4

          @J0Nes

          Unfortunately you can't (without modifying the Qt source). You have to work with the given normalization forms.


          If debugging is the process of removing software bugs, then programming must be the process of putting them in.

          ~E. W. Dijkstra

          1 Reply Last reply
          2
          • J Offline
            J Offline
            J0Nes
            wrote on 29 Oct 2021, 15:35 last edited by
            #5

            ok, too bad. Thanks for your help

            1 Reply Last reply
            0

            1/5

            29 Oct 2021, 14:24

            • Login

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