utf-8 source code files - and the .pro file
-
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 -
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 -
You are looking for IDE debug helpers for MSVC debugging and
-finput-charset=UTF-8
for the correct encoding. -
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 -
It's a compiler flag, no qmake CONFIG command: https://doc.qt.io/qt-5/qmake-variable-reference.html#qmake-cxxflags
-
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 -
@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.
-
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 -
@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
-
@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