Qt 6 support
DeadParrot opened this issue · 13 comments
On my system I ported the current osgQt master branch code to build with Qt 6. The changes required include:
- A few updates in OSGRenderer.cpp that are back-compatible with Qt 5 so this could be merged into the current master branch by itself.
- CMake file
Qt5
toQt6
and various other updates.
The CMake side is messier:
- I did not bother keeping Qt 4 and 5 support in my CMake files so I can't currently do a PR to osgQt master but maybe it could live on a
Qt6
branch for now until we merge the CMake bits (if that is what we want to do). - Keeping Qt 4 CMake support in there doesn't make sense since the old Qt 4 osgQt approach was removed but I'd vote for bringing it back in since it works with Qt 5 (but not Qt 6 since QGLWidget was removed).
- All but one of the examples still depend on the now-removed Qt 4 osgQt approach: they should be ported or removed unless the Qt 4 approach is reintegrated.
In summary, the C++ changes are simple but adding Qt 6 support to the CMake setup is kind of messy. It doesn't make sense to contribute here until there is a consensus on how best to add Qt 6 support and whether to resurrect the Qt 4 approach. Maybe separate osgQt4, osgQt5, and osgQt6 repos would be a better way to go. This/these should also be made a proper OSG companion project with releases tagged and in sync with the OSG version number. Since I got the discussion going on problems with osgQt and Qt versions that contributed to splitting out osgQt I am willing to contribute to making these improvements.
Can you for now fork and let us access the porting in the meantime?
I have been looking at the CMake code and is quite complex but, as you say, changes in Qt are quite small. So I would prefer to have a single solution splitting/redoing CMakeLists.txt files based on Qt version and a few ifdef (#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) and so on..) in C++ code.
Thanks,
David
I put the minimal Qt 6 changes in a topic/Qt6
branch of my fork at https://github.com/DeadParrot/osgQt/tree/topic/Qt6.
No QT_VERSION
checks are needed in the C++ source: all the C++ changes for Qt 6 are compatible with Qt 5 (but not Qt 4).
If the plan is to merge the CMake changes to support Qt 5 and 6 I think the logic has to respect -DDESIRED_QT_VERSION=5
or -DDESIRED_QT_VERSION=6
rather than just going with IF( Qt6Widgets_FOUND ) ... ELSEIF( Qt5Widgets_FOUND ) ...
logic the since many systems will have both Qt 5 and 6 installed so the developer needs to be able to choose the Qt to build against.
Thanks for the fork @DeadParrot and, yes, you are right, better use -DDESIRED_QT_VERSION
Hello @DeadParrot , I just looked at your modifications here : DeadParrot@c4d48d1
I wanted to tell you that I did essentially the same thing on my side at the beginning of October 2021. For the file src/osgQOpenGL/OSGRenderer.cpp, indeed most of the changes are compatible with Qt5 at the exception of one line, line 356 :
m_osgWinEmb->getEventQueue()->mouseMotion(event->position().x() * m_windowScale, event->position().y() * m_windowScale);
---> Indeed with Qt5.12.11 we need to keep the 'old' one : m_osgWinEmb->getEventQueue()->mouseMotion(event->x() * m_windowScale, event->y() * m_windowScale);
PS: as you may have read, I tested with Qt5.12.11 and I guess you didn't have this problem because you probably tested with Qt5.15.x (which introduces most things for Qt6) ?
But it is very good news that we have arrived at much the same thing. :-))
Hi @mtola. Thanks for the feedback. Nice that we arrived at the same place!
Yes, I was only testing on Qt 5.15.x so I missed that. I guess something like this would make it work on all versions of Qt 5 and 6:
#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
m_osgWinEmb->getEventQueue()->mouseMotion(event->position().x() * m_windowScale,
event->position().y() * m_windowScale);
#else
m_osgWinEmb->getEventQueue()->mouseMotion(event->x() * m_windowScale,
event->y() * m_windowScale);
#endif
As I described above, I'm not sure it makes sense to try and make this branch support Qt 5 and 6 since the old branch already supports 4 and 5, but if the osgQt maintainers decide to do that then this change is needed. I'm not sure there is much maintenance going on though so maybe we should ask Robert Osfield to let us set up an osgQt6 project?
Yes, exactly, just a test to properly support Qt5 and Qt6. I am OK with this test. ;-)
For me it is very important to properly support Qt5 and Qt6. We have just seen that the cost is also low.
Originally the osgQt module was an integral part of OSG then for several years it was extracted from OSG. I think Robert no longer handles this. Moreover, for 2/3 years he seems very busy with VulkanSceneGraph.
As you have a fork with just one commit in advance, I think you have to finish the little work that remains (especially with the Qt5/Qt6 test added today just above but also the small differences in the cmake files for proper detection and management of Qt5 or Qt6 libraries -> a new lib with Qt6: OpenGLWidgets, qt5_wrap_cpp/qt6_wrap_cpp, etc...) and then simply submit a Pull Request here. ;-)
The osgQt module will then be able to support Qt5 and Qt6. :-))
@mtola I'm fine with having Qt 5 and 6 support in the code and I don't think it would be hard to do that in the CMake setup but someone has to make it handle DESIRED_QT_VERSION
and carefully remove the Qt4 stuff and test that with Qt 5 and 6. I'd rather hear from the maintainers that they are on board with this plan before investing that effort only to have a PR ignored for months/years. Plus I am swamped and probably couldn't get to it for months.
Another complication is that the former "Qt4" approach actually works in Qt5 so some discussion should be had about whether keeping that around in a Qt5 branch has any value. I used that approach for a while in Qt5 until I got the new osgQOpenGL approach to work for my application.
If there are no active maintainers here then we should contact Robert about taking this over and make sure we have the Qt4 support correctly archived in the topic/Qt4 branch before we strip that out. Since I helped motivate the separation of osgQt I don't mind contributing here.
Hi @mtola and @DeadParrot, I'm the original co-author and still the maintainer on this project but since I changed companies three years ago, I'm no longer daily involved with OpenSceneGraph and Qt projects...
If any of you wants to step up, I'm ok to contact Robert and ask him to give you maintainer rights on this project !
I handed over management for vsgQt as don't have the required Qt expertise to support the project. If @mathieu needs to pass on the management I'm happy to grant write access to others.
I haven't closely followed the various threads/contributions to vsgQt so am not in position to know who would be appropriate to open out write access to. @mathieu could you decide who would be appropriate?
Also knowing who would be willing to take over would be useful too.
I would consider being a co-maintainer on this with @mtola and/or others but my time is very limited and I have no deep OpenGL expertise to offer.
It was finally decided that in my next project we would no longer use OSG so I will gradually move away from OSG.
Hi,
I'm trying to build @DeadParrot's port on Ubuntu 22.04 LTS, has anyone tried that yet?
I cloned and installed OpenSceneGraph and then when building osgqt it says:
/usr/bin/ld: cannot find -lWidgets: No such file or directory
/usr/bin/ld: cannot find -lOpenGLWidgets: No such file or directory
collect2: error: ld returned 1 exit status
make[2]: *** [examples/osgviewerQt/CMakeFiles/example_osgviewerQt.dir/build.make:117: bin/osgviewerQt] Error 1
make[1]: *** [CMakeFiles/Makefile2:199: examples/osgviewerQt/CMakeFiles/example_osgviewerQt.dir/all] Error 2
make: *** [Makefile:136: all] Error 2
I forgot to update my comment, it does build when I build OSG myself. I had issues using the Ubuntu package of osg.
I build like this
# Build and install OpenSceneGraph
git clone https://github.com/openscenegraph/OpenSceneGraph.git
cd OpenSceneGraph
# A few bug fixes after OpenSceneGraph-3.6.5
git switch --detach 683403244a489fe3e71f1533580c22e099774a36
mkdir build
cmake -S . -B build \
-DCMAKE_INSTALL_PREFIX=$install_path \
-DBUILD_OSG_DEPRECATED_SERIALIZERS:BOOL="0" \
-DOpenGL_GL_PREFERENCE="LEGACY"
make -C build install
cd ..
# Build and install osgQT
git clone https://github.com/DeadParrot/osgQt.git
# TODO: master if this is merged in the future (fingers crossed)
cd osgQt
git switch topic/Qt6
mkdir build
# Build in release mode
cmake -S . -B build \
-DCMAKE_INSTALL_PREFIX:PATH=$install_path \
-DOSG_DIR:PATH="$install_path/include" \
-DCMAKE_BUILD_TYPE="Release" \
-DOpenGL_GL_PREFERENCE="LEGACY" \
-DBUILD_OSG_EXAMPLES:BOOL="0"
# Build in debug mode
make -C build install
cmake -S . -B build \
-DCMAKE_INSTALL_PREFIX:PATH=$install_path \
-DOSG_DIR:PATH="$install_path/include" \
-DCMAKE_BUILD_TYPE="Debug" \
-DOpenGL_GL_PREFERENCE="LEGACY" \
-DBUILD_OSG_EXAMPLES:BOOL="0"
make -C build install
cd ..