Using Qt with OpenGl

I am using MacOS 10.15.2 and Geant4.10.06

I have been able to configure and build Geant4 with Qt after some struggle. Now my problem is OpenGL opens as it did before without the Qt GUI. I have listed my step by step process for building Geant4 with Qt.

If you know what I’ve done wrong or what I need to do please let me know.

Compiling with Qt

Attempt 1

• Downloaded Qt 5 Open source binary for MacOS
• Followed installer and selected package categories latest releases
• Launched Qt creator
• Configured Geant4 with Multithreaded, Install Data, OpenGL X11, Qt
• Qt_QMAKE_EXECUTABLE NOT FOUND

CMake Error at /Applications/CMake.app/Contents/share/cmake-3.16/Modules/FindQt4.cmake:1314 (message):
Found unsuitable Qt version “” from NOTFOUND, this code requires Qt 4.x
Call Stack (most recent call first):
cmake/Modules/Geant4InterfaceOptions.cmake:117 (find_package)
cmake/Modules/G4CMakeMain.cmake:64 (include)
CMakeLists.txt:50 (include)
• Set Qt_QMAKE_EXECUTABLE to Qt app
• Could not compile

Attempt 2

• Followed instructions on building Qt from Git Hub
• …/qt5/configure -developer-build -opensource -nomake examples -nomake tests
Did not work
• Project ERROR: You cannot configure qt separately within a top-level build.
• Ran the Configure executable
• Ran make -j8
• Ran make install
• Installed into /usr/local/Qt-5.12.7
• Attempted to cmake Geant4 with GEANT4_USE_QT=on
Got error

CMake Error at /Applications/CMake.app/Contents/share/cmake-3.16/Modules/FindQt4.cmake:1314 (message):
Found unsuitable Qt version “5.12.7” from /usr/local/Qt-5.12.7/bin/qmake,
this code requires Qt 4.x
Call Stack (most recent call first):
cmake/Modules/Geant4InterfaceOptions.cmake:117 (find_package)
cmake/Modules/G4CMakeMain.cmake:64 (include)
CMakeLists.txt:50 (include)

The Geant4 installation guide says
“Qt5 and OpenGL libraries and headers. Qt4 will be searched for as a fallback if Qt5 cannot be located but use of Qt4 in Geant4 is now deprecated.”
• Set CMAKE_INSTALL_PREFIX to /usr/local/Qt-5.12.7
• Successful configuration and generation!
• Went into Geant4 build directory and built Geant4
• Built and ran example B1, OpenGL opened without Qt

Just to be sure, did you use that as written, or as CMAKE_PREFIX_PATH? The latter is the correct one.

Otherwise, when you run exampleB1, what output do you see?

I tried the CMAKE_INSTALL_PREFIX and got the same result

When I run the executable exampleB1 I get an OpenGL window without Qt

I have attached a screenshot of my exampleB1.

Thanks for the info! Note that CMAKE_INSTALL_PREFIX is where Geant4 (or the package being built) will be installed if you do make install. CMAKE_PREFIX_PATH is a set of paths under which CMake will search for dependencies of the one being built. SO in this case, CMAKE_PREFIX_PATH should be set to /usr/local/Qt-5.12.7.

However, as the CMake configuration showed, Geant4 did pick up Qt at the configuration step, so should have been compiled with support. Building exampleB1 against that should then use Qt by default, but @Allison and @lgarnier can confirm that.

All I can suggest is to confirm that you are using the expected build/install of Geant4 when building exampleB1. If that’s right, then find the file named Geant4Config.cmake under the build/install prefix for that Geant4, and find the section beginning:

# - Qt (UI and Vis!)
set(Geant4_qt_FOUND ...)

Geant4_qt_FOUND should be ON or similar, and there should also be a variable Geant4_USES_QT5 set to ON or similar. Check those first, and we can then see if the issue is with the Geant4 build/install, or that of the example.

I tried setting CMAKE_INSTALL_PREFIX to /usr/local/Qt-5.12.7 but got the same result.

I found the Geant4Config.cmake and saw:

- Qt (UI and Vis!)

set(Geant4_qt_FOUND ON)
set(Geant4_USES_QT5 1)
if(Geant4_qt_FOUND)

Must always refind Qt5 to recreate imported targets. Because these

are in the public interface, always need linking.

if(Geant4_USES_QT5)
find_dependency(Qt5Core REQUIRED)
find_dependency(Qt5Gui REQUIRED)
find_dependency(Qt5Widgets REQUIRED)
find_dependency(Qt5OpenGL REQUIRED)
find_dependency(Qt5PrintSupport REQUIRED)
else()
find_dependency(Qt4 REQUIRED QtCore QtGui QtOpenGL)
endif()

Which I think is what I should be seeing if Qt was working properly.

I also saw when I was configuring in CMake I saw QT_QMAKE_EXECUTABLE=NOTFOUND. So that may be an issue.

and when Geant4 was building I saw:

[ 97%] Building CXX object source/visualization/OpenGL/CMakeFiles/G4OpenGL.dir/include/moc_/Users/shawn/Thesis/geant4.10.06-build/source/visualization/OpenGL/include/G4OpenGLQtExportDialog.cpp.o
/Users/shawn/Thesis/geant4.10.06-build/source/visualization/OpenGL/include/moc_/Users/shawn/Thesis/geant4.10.06-build/source/visualization/OpenGL/include/G4OpenGLQtExportDialog.cpp:9:10: warning:
non-portable path to file
‘"…/…/…/…/…/…/…/…/…/…/…/…/…/…/…/Thesis/geant4.10.06/source/visualization/OpenGL/include/G4OpenGLQtExportDialog.hh"’;
specified path differs in case from file name on disk [-Wnonportable-include-path]
…"…/…/…/…/…/…/…/…/…/…/…/…/…/…/…/thesis/geant4.10.06/source/visualization/OpenGL/include/G4OpenGLQtExportDialog.hh"
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
“…/…/…/…/…/…/…/…/…/…/…/…/…/…/…/Thesis/geant4.10.06/source/visualization/OpenGL/include/G4OpenGLQtExportDialog.hh”

Which was repeated three times and once at [7%]

Have you checked what is inside “/usr/local/Qt-5.12.7”?
I guess the path in CMAKE_INSTALL_PREFIX should be instead something like…
/usr/local/Qt-5.12.7/5.12.7/clang_64
where lib/bin/include are located?

Hello, I’m new in geant4. I installed geant4 but couldn’t understand how use xcode or qt to make project. Qt and Xcode see only cmake file and don’t see libraries. Could you help me what need to do? I use MacOs 10.15.2 Geant4.10.06

Screen Shot 2020-02-17 at 6.57.23 PM

This is what is in my /usr/local/Qt-5.12.7.

The layout looks correct, so can you please try setting CMAKE_PREFIX_PATH instead of CMAKE_INSTALL_PREFIX to point to that path ?

I just tried CMAKE_PREFIX_PATH=/usr/local/Qt-5.12.7 but OpenGL was still opened without QT. My CMake said QT_QMAKE_EXECUTABLE NOTFOUND, maybe that is saying something that I’ve got to fix. I just don’t know how.

If you rebuilt Geant4 (not the executable) from the same build directory with the new CMAKE_PREFIX_PATH, it’s likely CMake cached the results of the previous build. If that’s what was done, try removing the CMakeCache.txt file, then rerun cmake:

$ cmake -DCMAKE_PREFIX_PATH=/usr/local/Qt-5.12.7 -DGEANT4_ENABLE_QT=ON

Nope, that should be:

$ cmake -DCMAKE_PREFIX_PATH=/usr/local/Qt-5.12.7 -DGEANT4_USE_QT=ON <pathtogeant4src>

Post any output from that, plus the regenerated CMakeCache.txt file, then try rebuilding.
If that’s successful, then from the Geant4 build directory run:

$./geant4-config --help

It should print a help message, including a list of all configured/built features. Post that here as well.

The rebuilding seemed to work but I rebuilt exampleB1 and executed it and got an OpenGL window without QT. I always delete everything in the build folders before I rebuild.


CMakeCache.txt (44.4 KB) CMakeCache.txt

The only thing in the help message that seems like it could be pertinent is libs-without -gui and flags-without-gui

Hi,

I have found the same behavior with Qt when was installing Geant4 on the Windows machine.
Compilation with older version of Qt(5.10) have fixed this problem in my case.

Regards,
Volodymyr

O.k., so the build of Geant4 looks to have Qt support. Could you post the exact steps you then used to configure, build (with make VERBOSE=1), and run your application please? In addition, please post all output to the terminal when you start up the application - it’s important we see all of it as this will indicate which vis drivers were used.