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. utf-8 source code files - and the .pro file

utf-8 source code files - and the .pro file

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 2 Posters 1.9k 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.
  • H Offline
    H Offline
    HoMa
    wrote on 6 Mar 2021, 22:13 last edited by
    #1

    Hallo!
    I have a question to the .pro file format and would be glad if someone could help:
    I have quite some german "umlaute" in my source code - like Ä or ü - and if I build my project with MSVC tool chain the following entries in the .pro file will make this work:

    win32:QMAKE_CXXFLAGS += /utf-8
    win32:QMAKE_CXXFLAGS += /FS
    

    However ... debugging in not so good with the MSVC tools - I can not see the content of variables and stuff. So I switch to mingw - but this does not work with the switches mentioned above.
    So... what is the "compatible" way to tell all compilers, that my source files are utf-8? Or ... are there alternatives to achieve the same thing?
    Thank you in advance - Holger

    1 Reply Last reply
    0
    • H Offline
      H Offline
      HoMa
      wrote on 8 Mar 2021, 08:40 last edited by
      #5

      Thank you again!

      This pointed me to what looks like the correct solution: the page you pointed to, shows both: The config value

      CONFIG+=utf8_source
      

      AND the compiler option

      -finput-charset=UTF-8
      

      The compiler switch - however - gives me an error with MSVC (unknown compiler switch). But the good news: the CONFIG seems to work for both: MinGw and MSVC.

      best regards
      Holger

      1 Reply Last reply
      0
      • C Offline
        C Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on 7 Mar 2021, 08:13 last edited by
        #2

        You are looking for IDE debug helpers for MSVC debugging and -finput-charset=UTF-8 for the correct encoding.

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        1 Reply Last reply
        3
        • H Offline
          H Offline
          HoMa
          wrote on 8 Mar 2021, 08:23 last edited by
          #3

          Thank you, Christian.
          On your link about IDE debug helpers: I may not have been very clear: In visual studio IDE I can see QStrings, actually. I use VS2019 with a qt plugin. However: I would prefer QtCreator (it is slower, but I am used to the keyboard shortcuts and did not find time to reconfigure VS ;) )
          So the problem is: I can not see QStrings and other Q_OBjECTS while debugging in QtCreator, if the programs are compiled with the microsoft compiler.

          On the source code encoding: Did you mean smth like

          CONFIG +=-finput-charset=UTF-8
          

          ? This works fine with mingw tool chain. If I switch the project settings to msvc comiler (still in QtCreator) the german Umlaute will be displayed incorrectly.

          Best regards
          Holger

          1 Reply Last reply
          0
          • C Offline
            C Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on 8 Mar 2021, 08:29 last edited by
            #4

            It's a compiler flag, no qmake CONFIG command: https://doc.qt.io/qt-5/qmake-variable-reference.html#qmake-cxxflags

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            1 Reply Last reply
            2
            • H Offline
              H Offline
              HoMa
              wrote on 8 Mar 2021, 08:40 last edited by
              #5

              Thank you again!

              This pointed me to what looks like the correct solution: the page you pointed to, shows both: The config value

              CONFIG+=utf8_source
              

              AND the compiler option

              -finput-charset=UTF-8
              

              The compiler switch - however - gives me an error with MSVC (unknown compiler switch). But the good news: the CONFIG seems to work for both: MinGw and MSVC.

              best regards
              Holger

              1 Reply Last reply
              0
              • C Offline
                C Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on 8 Mar 2021, 08:42 last edited by
                #6

                @HoMa said in utf-8 source code files - and the .pro file:

                gives me an error with MSVC

                You already had the compiler switch for MSVC. So use that for msvc and -finput-charset=UTF-8 for gcc.

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                1 Reply Last reply
                2
                • H Offline
                  H Offline
                  HoMa
                  wrote on 8 Mar 2021, 08:47 last edited by
                  #7

                  Hi Christian, thank you for this comment.
                  You are right: The /utf8 /fs flags work on MSVC - but my goal was to have only one .pro file that works without change for both configurations. I don't know how to set cxx_clags differently for different compilers.
                  However: the CONFIG thing works with MinGw AND with MSVC.

                  To anybody with similar problems: The analysis was a bit cumbersome, until I learned that one has to do a rebuild all after changing the .pro file. My original assumption, that this will be done automatically was wrong (which might be considered a bug ...)

                  Best regards
                  Holger

                  1 Reply Last reply
                  0
                  • C Offline
                    C Offline
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on 8 Mar 2021, 08:51 last edited by
                    #8

                    @HoMa said in utf-8 source code files - and the .pro file:

                    I don't know how to set cxx_clags differently for different compilers.

                    Read the docs: https://doc.qt.io/qt-5/qmake-tutorial.html#adding-platform-specific-source-files

                    win32:msvc
                    

                    for example

                    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                    Visit the Qt Academy at https://academy.qt.io/catalog

                    1 Reply Last reply
                    2
                    • H Offline
                      H Offline
                      HoMa
                      wrote on 8 Mar 2021, 09:03 last edited by
                      #9

                      @Christian-Ehrlicher said in utf-8 source code files - and the .pro file:

                      win32:msvc

                      Thanks for that piece! That was what I was searching for all along!
                      I was not aware, that "msvc" works as a platform switch.
                      But no - I was not able to find this in the documentation. "msvc" is not on that page.

                      However: For completness this is the alternate suggestion from Christian which also works, because MinGw does the utf-8 thing correctly by default:

                      win32:msvc:QMAKE_CXXFLAGS += /utf-8
                      win32:msvc:QMAKE_CXXFLAGS += /FS
                      

                      It has the same effect as

                      CONFIG+=utf8_source
                      
                      1 Reply Last reply
                      0

                      4/9

                      8 Mar 2021, 08:29

                      • Login

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