Solved How to change Qt6 Windows appliaction defaulting to UNICODE?
-
Hi,
I build a Windows application with CMake and Qt6, it looks like when I build it as a GUI application (WIN32 in add_executable: https://cmake.org/cmake/help/latest/command/add_executable.html) it is set to UNICODE, but when I build it as Console application it is set to Multi-byte character set. With Qt5 it used to set to multi-byte character set in both cases. My question is how I can create Qt6 Windows application with CMake using multi-byte character set instead of UNICODE. I mean I can change the project properties in Visual Studio (which is created by CMake from CMake code), but that is not really an option, because it gets lost on every CMake run. I don't really understand if this is caused by Qt, CMake or Visual Studio, but sinse I see the difference between Qt5 and Qt6 (everything else is the same) I came here.PS: my application uses Qt6Core5Compat module.
-
@Gertio said in How to change Qt6 Windows appliaction defaulting to UNICODE?:
So you think I should use WaitNamedPipeA() then?
Yes
But I came here because I thought that you can affect UNICODE definition in the first place, because as I said, Qt5 does not define it, only Qt6 and only if building GUI application (not console application).
This change seems to be on purpose: QTBUG-89951. According to the patch description you can disable UNICODE definition by using
qt6_disable_unicode_defines
in CMake. -
@Gertio said in How to change Qt6 Windows appliaction defaulting to UNICODE?:
it is set to Multi-byte character set
How do you know this and why do you care? Do you use WinAPI calls directly?
-
I know it because I can see it in the Project properties in Visual Studio: Properties -> Configuration properties -> advanced -> character set.
Yes, I use direct WinAPI calls and UNICODE makes compilation of my project fail.
-
_UNICODE is defined by default for Qt5 and Qt6. I'm not aware that one can change this setting and I don't see why it is needed. Please show us a usecase for your question.
-
@Gertio said in How to change Qt6 Windows appliaction defaulting to UNICODE?:
Yes, I use direct WinAPI calls and UNICODE makes compilation of my project fail.
Slightly off topic perhaps, but if changing from UNICODE not being defined to defined breaks your code it means you were doing it wrong in the first place. The whole point of it is that you can write unicode-portable code and it should compile either way.
It means you made assumptions and used the "universal" function versions with non-universal parameter types e.g. doing things like
SetWindowText(hWnd, "foo")
where you should either use the explicit version
SetWindowTextA(hWnd, "foo")
or the "universal" parameters
SetWindowText(hWnd, _T("foo"))
So if possible - fix your code first.
-
Thank you for the responses. I use
pipe_[i].handle = CreateNamedPipe(pipename.c_str(), open_mode | FILE_FLAG_OVERLAPPED, PIPE_WAIT, MAX_CLIENTS, PIPE_BUFSIZE, PIPE_BUFSIZE, PIPE_TIMEOUT, NULL);
and
WaitNamedPipe(inPipeName().c_str(), 0)
Sorry, but this is not my code, I maintain Windows installation for an open source project, which has been around for more than 25 years by now. In the above 2 cases
pipename
isconst std::string
andinPipeName()
returnsconst std::string
, which get converted toconst char*
by.c_str()
. So you think I should useWaitNamedPipeA()
then? That would be of course an option. But I came here because I thought that you can affect UNICODE definition in the first place, because as I said, Qt5 does not define it, only Qt6 and only if building GUI application (not console application). -
@Gertio said in How to change Qt6 Windows appliaction defaulting to UNICODE?:
So you think I should use WaitNamedPipeA() then?
Yes
But I came here because I thought that you can affect UNICODE definition in the first place, because as I said, Qt5 does not define it, only Qt6 and only if building GUI application (not console application).
This change seems to be on purpose: QTBUG-89951. According to the patch description you can disable UNICODE definition by using
qt6_disable_unicode_defines
in CMake.