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. Remove -utf-8 flag from MSVC2019 call

Remove -utf-8 flag from MSVC2019 call

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 4.2k 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.
  • J Offline
    J Offline
    Joulz
    wrote on last edited by
    #1

    Hi all,

    My files are saved using Windows1252 but that leads to warnings using Qt 6.2.3 MSVC2019.

    ..\msvc19_test\mainwindow.cpp(1): warning C4828: The file contains a character starting at offset 0xee that is illegal in the current source character set (codepage 65001).
    

    I think it is caused by the -utf-8 flag given to the compiler.

    cl -c (...) -utf-8 (...)
    

    How can I remove this flag from the default compiler call? I tried

    QMAKE_CXXFLAGS -= -utf-8
    

    in the .pro that contains the affected sources, but it had no effect on the resulting call.

    To reproduce it, create a new Qt Widgets project using Windows 1252, Qt 6.2.3 MSVC2019, add a comment with an umlaut somewhere, and build it.

    MainWindow::MainWindow(QWidget *parent)
        : QMainWindow(parent)
        , ui(new Ui::MainWindow)
    {
        // äöüûôîéèÄÖÜÎÔÛ
        ui->setupUi(this);
    }
    

    Converting all source code to UTF-8 would be possible, but a huge hassle. Especially since MS docs states that the default system encoding is used, if the flag is not set.

    Thx for any ideas.

    1 Reply Last reply
    0
    • hskoglundH Offline
      hskoglundH Offline
      hskoglund
      wrote on last edited by
      #4

      Indeed, having every team member patch this and do it again for Qt version 6.3. 6.4. 6.5..., not ideal :-(
      Turns out this patch can be accomplished in a more portable/sustainable way: if you look at that msvc-version.conf line 74, it sets a variable called QMAKE_CFLAGS_UTF8_SOURCE.
      And that qmake variable can be changed in your .pro file.

      To test, restore line 74 in msvc=version.conf file to its original contents and instead try this in your .pro file

      message (Before: $$QMAKE_CFLAGS_UTF8_SOURCE)
      QMAKE_CFLAGS_UTF8_SOURCE = /source-charset:windows-1252
      message (After: $$QMAKE_CFLAGS_UTF8_SOURCE)
      

      Now if you run qmake on the .pro file, it should say:
      ...
      Project MESSAGE: Before: -utf-8
      Project MESSAGE: After: /source-charset:windows-1252
      ...
      I was worried that there was more stuff in that qmake variable that will be gone by reassigning it, that's why I had those message lines. They can be removed once you have it working :-)

      J 1 Reply Last reply
      1
      • hskoglundH Offline
        hskoglundH Offline
        hskoglund
        wrote on last edited by
        #2

        Hi, changing MSVC 2019 compiler options inside Qt Creator can be frustrating, instead I've resorted to directly patching the msvc-version.conf file in the C:\Qt\6.2.3\msvc2019_64\mkspecs\common directory.

        In your case, try patching iine 74 in that file.

        Original contents:

        ...
            # -utf-8 compiler option for Visual Studio 2015 Update 2
        greaterThan(QMAKE_MSC_FULL_VER, 190023918): QMAKE_CFLAGS_UTF8_SOURCE = -utf-8
        }
        ...
        

        to

        ...
            # -utf-8 compiler option for Visual Studio 2015 Update 2
            greaterThan(QMAKE_MSC_FULL_VER, 190023918): QMAKE_CFLAGS_UTF8_SOURCE = /source-charset:windows-1252
        }
        ...
        
        J 1 Reply Last reply
        1
        • hskoglundH hskoglund

          Hi, changing MSVC 2019 compiler options inside Qt Creator can be frustrating, instead I've resorted to directly patching the msvc-version.conf file in the C:\Qt\6.2.3\msvc2019_64\mkspecs\common directory.

          In your case, try patching iine 74 in that file.

          Original contents:

          ...
              # -utf-8 compiler option for Visual Studio 2015 Update 2
          greaterThan(QMAKE_MSC_FULL_VER, 190023918): QMAKE_CFLAGS_UTF8_SOURCE = -utf-8
          }
          ...
          

          to

          ...
              # -utf-8 compiler option for Visual Studio 2015 Update 2
              greaterThan(QMAKE_MSC_FULL_VER, 190023918): QMAKE_CFLAGS_UTF8_SOURCE = /source-charset:windows-1252
          }
          ...
          
          J Offline
          J Offline
          Joulz
          wrote on last edited by Joulz
          #3

          @hskoglund Thank you, that is exactly what I was searching for.

          I was looking for that in "%QTDIR%\mkspecs\common\msvc-desktop.conf" and missed the comment at the top (facepalm)

          It looks as if that has to be changed by each developer for all Qt versions that might behave like this in the future. Is there a way to tie this compiler option to the project? An optimal solution would be something that could be pushed into a repo for every team member to use. That's why I tried to use the .pro files.

          Is there a way to accomplish this?
          Can I push this edited .conf file and reference it somewhere in the project? (Kit settings have a "Qt mkspec" field -> again a setting everybody would need to change?)

          Thank you again for that simple fix

          1 Reply Last reply
          0
          • hskoglundH Offline
            hskoglundH Offline
            hskoglund
            wrote on last edited by
            #4

            Indeed, having every team member patch this and do it again for Qt version 6.3. 6.4. 6.5..., not ideal :-(
            Turns out this patch can be accomplished in a more portable/sustainable way: if you look at that msvc-version.conf line 74, it sets a variable called QMAKE_CFLAGS_UTF8_SOURCE.
            And that qmake variable can be changed in your .pro file.

            To test, restore line 74 in msvc=version.conf file to its original contents and instead try this in your .pro file

            message (Before: $$QMAKE_CFLAGS_UTF8_SOURCE)
            QMAKE_CFLAGS_UTF8_SOURCE = /source-charset:windows-1252
            message (After: $$QMAKE_CFLAGS_UTF8_SOURCE)
            

            Now if you run qmake on the .pro file, it should say:
            ...
            Project MESSAGE: Before: -utf-8
            Project MESSAGE: After: /source-charset:windows-1252
            ...
            I was worried that there was more stuff in that qmake variable that will be gone by reassigning it, that's why I had those message lines. They can be removed once you have it working :-)

            J 1 Reply Last reply
            1
            • hskoglundH hskoglund

              Indeed, having every team member patch this and do it again for Qt version 6.3. 6.4. 6.5..., not ideal :-(
              Turns out this patch can be accomplished in a more portable/sustainable way: if you look at that msvc-version.conf line 74, it sets a variable called QMAKE_CFLAGS_UTF8_SOURCE.
              And that qmake variable can be changed in your .pro file.

              To test, restore line 74 in msvc=version.conf file to its original contents and instead try this in your .pro file

              message (Before: $$QMAKE_CFLAGS_UTF8_SOURCE)
              QMAKE_CFLAGS_UTF8_SOURCE = /source-charset:windows-1252
              message (After: $$QMAKE_CFLAGS_UTF8_SOURCE)
              

              Now if you run qmake on the .pro file, it should say:
              ...
              Project MESSAGE: Before: -utf-8
              Project MESSAGE: After: /source-charset:windows-1252
              ...
              I was worried that there was more stuff in that qmake variable that will be gone by reassigning it, that's why I had those message lines. They can be removed once you have it working :-)

              J Offline
              J Offline
              Joulz
              wrote on last edited by
              #5

              @hskoglund
              I just tried it out, and it works as expected.
              Thanks again for the help. I will mark your last post as the answer and close this as solved.

              Thx !!!

              Q 1 Reply Last reply
              1
              • J Joulz

                @hskoglund
                I just tried it out, and it works as expected.
                Thanks again for the help. I will mark your last post as the answer and close this as solved.

                Thx !!!

                Q Offline
                Q Offline
                QtTester
                wrote on last edited by
                #6

                @Joulz Hi, Can we ignore this warning?
                I try:

                QMAKE_CXXFLAGS_WARN_ON -= -w44828
                #or -w1 -w2 -w3
                

                all didnot work.

                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 Extensions
                • Unsolved