Problem 2599

Summary: [Installation Error] Install with Qt6 in Windows
Product: Geant4 Reporter: evandde
Component: interfacesAssignee: Gabriele Cosmo <Gabriele.Cosmo>
Status: RESOLVED FIXED    
Severity: minor CC: Ben.Morgan, niso2012
Priority: P4    
Version: 11.2   
Hardware: PC   
OS: Windows   
URL: https://geant4-forum.web.cern.ch/t/installation-error-install-with-qt6-in-windows/11879
Attachments: Corrected file
Corrected file

Description evandde 2024-03-11 16:29:46 CET
Geant4 Version: 11.2 & 11.2.patch1
Operating System: Windows 11
Compiler/Version: MSVC 2022
CMake Version: 3.28.0-msvc1

Hello,

I’ve been experiencing compilation issues while attempting to install Geant4 versions 11.2 (and also 11.2.patch1) with Qt6 on a Windows 11 environment. The errors arise primarily from type conversion conflicts between char arrays and LPCWSTR in the G4Win32.cc and G4UIWin32.cc source files. These errors suggest that conversions or casts are necessary to proceed with the installation.

Below are the specific error messages encountered during the build process:

For G4Win32.cc:

C:\geant4\geant4-v11.2.1\source\interfaces\implementation\src\G4Win32.cc(68,23): error C2440: '=': cannot convert from 'char [8]' to 'LPCWSTR'
C:\geant4\geant4-v11.2.1\source\interfaces\implementation\src\G4Win32.cc(69,24): error C2440: '=': cannot convert from 'char [8]' to 'LPCWSTR'
C:\geant4\geant4-v11.2.1\source\interfaces\implementation\src\G4Win32.cc(73,9): error C2664: 'HWND CreateWindowExW(DWORD,LPCWSTR,LPCWSTR,DWORD,int,int,int,int,HWND,HMENU,HINSTANCE,LPVOID)': cannot convert argument 2 from 'char [8]' to 'LPCWSTR'
...
For G4UIWin32.cc:

C:\geant4\geant4-v11.2.1\source\interfaces\implementation\src\G4UIWin32.cc(101,23): error C2440: '=': cannot convert from 'char [10]' to 'LPCWSTR'
C:\geant4\geant4-v11.2.1\source\interfaces\implementation\src\G4UIWin32.cc(102,24): error C2440: '=': cannot convert from 'char [10]' to 'LPCWSTR'
C:\geant4\geant4-v11.2.1\source\interfaces\implementation\src\G4UIWin32.cc(105,7): error C2664: 'int MessageBoxW(HWND,LPCWSTR,LPCWSTR,UINT)': cannot convert argument 2 from 'const char [45]' to 'LPCWSTR'
...

It is noteworthy that these issues do not occur under same installation options on Ubuntu, nor do they arise when integrating Geant4 11.2 and 11.2.patch1 with Qt5 on Windows 11, where the installation completes successfully.

I've tried below, and they didn't work:
- Add `/utf-8` in `CMAKE_CXX_FLAGS`
- Add additional code in G4Win32.cc & G4UIWin32.cc
  ```
  #ifdef _UNICODE
  typedef wchar_t TCHAR;
  #else
  typedef char TCHAR;
  #endif
  ```
Comment 1 Ben Morgan 2024-03-11 16:44:48 CET
Koichi (or Evan), could you reassign to Laurent Garnier or John Allison please?
Comment 2 John.Allison 2024-03-11 19:30:12 CET
Sorry, can't help here.
Comment 3 Gabriele Cosmo 2024-03-26 16:34:16 CET
Problem now fixed in the development branch.
Fixes will be included in next patch release.
Comment 4 Andrea 2024-06-29 05:13:11 CEST
Created attachment 868 [details]
Corrected file
Comment 5 Andrea 2024-06-29 05:13:35 CEST
Created attachment 869 [details]
Corrected file
Comment 6 Andrea 2024-06-29 05:17:10 CEST
Hello,

I have compiled the new release 11.2.2, but similar errors still occur on other files:

- source\visualization\OpenGL\src\G4OpenGLWin32Viewer.cc
- source\externals\g4tools\include\toolx\Windows\glarea

I have corrected them and G4 compile and run correctly with Qt 6.6.2. You can find my patch attached.
I cannot exclude that there could be other files with similar problems not used in my installation.

Andrea