Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Qt 6
  4. How to change Qt6 Windows appliaction defaulting to UNICODE?
Forum Updated to NodeBB v4.3 + New Features

How to change Qt6 Windows appliaction defaulting to UNICODE?

Scheduled Pinned Locked Moved Solved Qt 6
7 Posts 3 Posters 1.8k Views 1 Watching
  • 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.
  • G Offline
    G Offline
    Gertio
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    1
    • G Gertio

      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 is const std::string and inPipeName() returns const std::string, which get converted to const char* by .c_str(). So you think I should use WaitNamedPipeA() 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).

      Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #7

      @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.

      1 Reply Last reply
      3
      • Christian EhrlicherC Online
        Christian EhrlicherC Online
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #2

        @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?

        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
        1
        • G Offline
          G Offline
          Gertio
          wrote on last edited by Gertio
          #3

          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.

          Chris KawaC 1 Reply Last reply
          0
          • Christian EhrlicherC Online
            Christian EhrlicherC Online
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #4

            _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.

            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
            1
            • G Gertio

              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.

              Chris KawaC Offline
              Chris KawaC Offline
              Chris Kawa
              Lifetime Qt Champion
              wrote on last edited by
              #5

              @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.

              1 Reply Last reply
              2
              • G Offline
                G Offline
                Gertio
                wrote on last edited by Gertio
                #6

                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 is const std::string and inPipeName() returns const std::string, which get converted to const char* by .c_str(). So you think I should use WaitNamedPipeA() 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).

                Chris KawaC 1 Reply Last reply
                0
                • G Gertio

                  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 is const std::string and inPipeName() returns const std::string, which get converted to const char* by .c_str(). So you think I should use WaitNamedPipeA() 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).

                  Chris KawaC Offline
                  Chris KawaC Offline
                  Chris Kawa
                  Lifetime Qt Champion
                  wrote on last edited by
                  #7

                  @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.

                  1 Reply Last reply
                  3

                  • Login

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