Remove -utf-8 flag from MSVC2019 call
-
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.
-
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 :-) -
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 } ...
-
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 } ...
@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
-
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 :-) -
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 :-)@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 !!!
-
@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 !!!