Use QT with Geant in Windows

Hello I’m a Windows user. Currently Geant4 open the visualization by using OpenGl, but the images are small and I can’t rotate them.

See for example this image

So I wanted to open the visualization by using QT. I installed QT and in this topic Define a meniscus solid @evc said me to compile again Geant4 with the QT path

so I wrote

cmake -DCMAKE_INSTALL_PREFIX="C:\Program Files\geant4_10_06-install" "C:\Program Files\geant4_10_06" -DCMAKE_PREFIX_PATH="C:\Qt\5.15.0\winrt_x64_msvc2019"

and it said

GEANT4_USE_QT: Build Geant4 with Qt support

but when I run the simulation it still open it by OpenGl (indeed, when I run it …Geant 4 just write it found opengl

I don’t know if it could depend on some warning (or erro that I see during the Geant4 building after I do the commands
cmake --build . --config Release
cmake --build . --config Release --target install

here the log

log.txt (643.4 KB)

but even if see these errors Geant4 looks like working but it still use opengl instead of Qt…
Should I write any command to open by QT?
Thank you

Today, I also tried to

a. Delete the CmakeCache
b. Use the command
cmake -DCMAKE_INSTALL_PREFIX="C:\Program Files\geant4_10_06-install" "C:\Program Files\geant4_10_06" -DGEANT4_USE_QT=ON -DCMAKE_PREFIX_PATH="C:\Qt\5.15.0\winrt_x64_msvc2019"

but I get this error

Notice I’ve the same problem if I use C:\Qt\5.15.0\winrt_x86_msvc2019

a.Delete CmakeCache
b. cmake -DCMAKE_INSTALL_PREFIX="C:\Program Files\geant4_10_06-install" "C:\Program Files\geant4_10_06" -DCMAKE_PREFIX_PATH="C:\Qt\5.15.0\mingw81_32" -DGEANT4_USE_QT=ON

It says to fint Qt, but when I digit the command

cmake --build . --config Release --target install

I get many errors

here the log

Log.txt (326.6 KB)

Notice I’ve same problem if I use


So…what should I do to set QT?

@bmorgan, maybe, do you know how to fix this problem

The cmake invocation looks fine, so all I can spot is that the winrt/mingw builds of Qt don’t match the use of MSVC. IIRC, Qt should provide C:\Qt\5.15.0\msvc2019_64 that would be compatible, so try reconfiguring/rebuilding with that in the CMAKE_PREFIX_PATH.

@bmorgan I’m not sure if I understood…

Do you mean this path C:\Qt\5.15.0\winrt_x64_msvc2019?

Because if you mean that, as I wrote in my previous message, I got this error

Ps: Here directories that I’ve in Qt/5.15 directory


Depending on which Qt installer you used, it should have given you the opportunity to install msvc2019 and msvc2019_64 libraries. I think those will be required to use Qt with Geant4 on this machine.

Thank you @bmorgan
I’m installing again QT.
I’m selected all this to install



Do you think that I selected all the required packages to use QT with Geant4?

That should be sufficient!

Hello @bmorgan, I installed those Qt packages. I installed again Geant but when I runned an applicatio I got these errors:

I got these errors both if I run using visualization and not using it.

Then I downloaded the missing dll and I copied them in C:/system32 directory
but now I get this error
and I get it if I run with and without visualization

Do you know what should I do?

Ps. @bmorgan
Notice that I also tried to run the original B1 example, but I get that error

The failure to locate a DLL error is usually a symptom of the directory holding them noting being in the PATH environment variable. You should update that (just as you did to point to the Geant4 DLLs) to point to the directory holding the appropriate Qt5 DLLs. As you’re building for msvc2019_x64, first find the directory under C:\Qt\5.15.0\msvc2019_x64 which has Qt5Core.dll and then add that directory to the PATH.

At the same time, double check that all the data library environment variables are set as well as when running with Qt the error message on these not being set might induce the “0xc000007b” error.

Thank you @bmorgan

I solved this b downloading the dll and putting them in c:/windows/system32 but when I did it I got the “0xc000007b” error.

do you mean the environment variables for G4ABLA, g4ndl etc?
They are setted…indeed when I installed again without qt, geant4 worked fine.
Now I’m trying to install it again by using qt, but it I still get the 0xc000007b error

Download from where? From C:\Qt\5.15.0\msvc2019_x64? It’s likely that you’ve built a 64bit application but have the 32bit DLLs. You should delete the Qt DLLs in c:/windows/system32 and add where the DLLs are under C:\Qt\5.15.0\msvc2019_x64 to PATH, like for the Geant4 DLLs.

Thank you @bmorgan ! Setting the Path it worked!

Just last question please!

As you can see by the printscreen

Currently the unit is setted 5cm then targets are small. How can I change the unit in order to see a larger image?
Thank you

An extensive manual for visualisation options and commands is available in the Application Developer Guide.

Thank you @bmorgan !

I have the same posted probleme here (no interactive display of the geomitry just an image),
@bmorgan please what do you mean by “… delete the Qt DLLs in c:/windows/system32…”, delete this path in the environment variable or delete the Qt DLLs located in this folder “system32” whish i don’t find them?

Hi @Zazo when I tried to install QT the first time I didn’t set the path!

Install Geant in this way
cmake -DCMAKE_INSTALL_PREFIX="C:\Program Files\geant4_10_07-install" "C:\Program Files\geant4_10_07" DCMAKE_PREFIX_PATH="C:\Qt\5.15.0\msvc2019_x64" -DGEANT4_USE_QT=ON

Obviously change C:\Program Files\geant4_10_07-install C:\Program Files\geant4_10_07 C:\Qt\5.15.0\msvc2019_x64 writing respectively:

  1. The directory where you have to install G4
  2. The directory where you have G4 sources
  3. The directory where tou have QT for your system (in my case it’s a x64)

At the end of the installation, you have to set the enviroment variables…ie. you have to set the path where the DLLs (Qt5Widgets.dll, Qt5OpenGl, ecc) are under C:\Qt\5.15.0\msvc2019_x64 to PATH, like for the Geant4 DLLs (in my case C:\Qt\5.15.2\msvc2019_64\bin)

@faca87 thanks for the help, I’m following your method but I got this message with a lot of errors

I guess that in the command of geant4 installation could add -DGEANT4_USE_OPENGL_WIN32=ON, because in the book for application developers wrotten: The Qt driver requires the OpenGL library… So I add it , after the execution of EampleB1 I got an image not an interactive display (Qt doesn’t work!)

Here the CMakeCache.txt CMakeCache.txt (16.0 KB)

Hello, I’m not an expert, I just followed the help of @bmorgan
When I installed G4 using QT I didn’t write


it worked writing the command in my previous message…try to install g4 againg without that command. Otherwise, I’m sorry, but you have to wait for @bmorgan because I really don’t know the reason of that error

Thank you @faca87 , I understand :slightly_smiling_face:!