Skip to content

Conversation

@jcfr
Copy link
Member

@jcfr jcfr commented Nov 9, 2025

This pull request introduces support for Qt 6 while maintaining compatibility with Qt 5. The changes include:

  1. Generalizing CMake macros to handle Qt6 by using the CTK_QT_VERSION variable.
  2. Clarifying and improving the handling of Qt Designer plugin definitions and include directories for Qt5 and newer Qt versions.
  3. Updating various CMake scripts to support both Qt 5 and Qt 6, including necessary version checks and component additions.

Fixes #947


Add CMake configuration for Qt6 alongside Qt5

Enable building CTK with either Qt 5 or Qt 6 by updating CMake configuration and Qt component selection:

  • Allow CTK_QT_VERSION to be 5 or 6 (defaulting to 6 when Qt6_DIR is defined, otherwise 5), and validate its value.
  • Use common Qt APIs for both Qt 5 and Qt 6 where available (e.g. qt_add_resources, qt_create_translation, qt_wrap_cpp, plugin setup helpers).
  • Add required Qt 6 components when building with Qt 6, including Core5Compat, StateMachine, and OpenGLWidgets, while preserving existing Qt 5 behavior.
  • Restrict use of deprecated or Qt 5–only components:
    • Require XmlPatterns only with Qt 5.
    • Force CTK_USE_QTTESTING OFF with Qt 6, since QtTesting depends on XmlPatterns.
    • Disable CommandLine Modules components and applications that depend on XmlPatterns for Qt 6 builds.
    • Disable DICOM Application Hosting plug-ins and example applications that depend on QtSOAP for Qt 6 builds.
  • Update core, widgets, VTK widgets, and test CMakeLists to link against the appropriate Qt 5/Qt 6 targets based on CTK_QT_VERSION.

Related pull requests:

CTK updates

CTK updates

For future reference, the following pull requests fix deprecation warnings and are step toward supporting Qt6 and beyond:

PythonQt Updates (both upstream and our fork)

PythonQt Updates

@jamesobutler
Copy link
Contributor

Time to update the CI to also build a job with Qt6?

qtbase5-dev \

@jcfr jcfr linked an issue Nov 9, 2025 that may be closed by this pull request
@jcfr
Copy link
Member Author

jcfr commented Nov 9, 2025

Supersede the following:

This was referenced Nov 9, 2025
@jcfr
Copy link
Member Author

jcfr commented Nov 9, 2025

Time to update the CI to also build a job with Qt6?

Ditto. I will do so in the next hour or so.

@jcfr jcfr force-pushed the support-qt6 branch 2 times, most recently from d1e2171 to 87c81de Compare November 9, 2025 05:41
@jcfr
Copy link
Member Author

jcfr commented Nov 10, 2025

Issue specific to older Qt version using a stricter moc tool will be fixed by the following pull request:

@jcfr
Copy link
Member Author

jcfr commented Nov 11, 2025

Similarly to #1309 (comment), additional issues related to ctkDICOM classes that are specific to older Qt version using a stricter moc tool will be fixed by the following pull request:

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request introduces support for Qt 6 while maintaining backward compatibility with Qt 5. The implementation uses the CTK_QT_VERSION variable to conditionally configure CMake for either Qt version, with automatic detection defaulting to Qt 6 when Qt6_DIR is defined.

Key changes:

  • Generalized CMake macros to handle both Qt 5 and Qt 6 using CTK_QT_VERSION variable
  • Added Qt 6-specific components (Core5Compat, StateMachine, OpenGLWidgets, DesignerComponentsPrivate)
  • Disabled features that depend on Qt components unavailable in Qt 6 (XmlPatterns, QtSOAP)

Reviewed Changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
CMakeLists.txt Adds Qt version auto-detection, validation, and conditional disabling of Qt 6-incompatible features
CMake/ctkMacroSetupQt.cmake Updates Qt package discovery and component selection for both Qt 5 and Qt 6
CMake/ctkMacroSetupPlugins.cmake Generalizes Qt library path detection for both versions
CMake/ctkMacroBuildQtPlugin.cmake Updates Qt Designer plugin support and compile definitions for Qt 6
CMake/ctkMacroBuildPlugin.cmake Replaces Qt5-specific functions with version-agnostic equivalents
CMake/ctkFunctionGeneratePluginManifest.cmake Updates resource compilation to use generic Qt function
Libs/Core/CMakeLists.txt Adds Qt 6-specific dependencies (Core5Compat, StateMachine)
Libs/Widgets/CMakeLists.txt Adds Qt 6-specific OpenGLWidgets component
Libs/Widgets/Testing/Cpp/CMakeLists.txt Generalizes Qt Test and XmlPatterns linking for both versions
Libs/Visualization/VTK/Widgets/target_libraries.cmake Adds Qt 6 network and webkit library references
Libs/PluginFramework/Documentation/Snippets/EventAdmin-Intro/files.cmake Replaces Qt5-specific moc wrapper with generic version
.github/workflows/ci.yml Adds Qt 6 CI matrix testing alongside Qt 5

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

This comment was marked as outdated.

This change updates various CMake macros to handle Qt6 by using CTK_QT_VERSION.
It replaces hardcoded Qt5 references with version-agnostic code where possible.

This comment was marked as outdated.

This comment was marked as outdated.

jcfr and others added 3 commits November 11, 2025 00:54
Qt5’s `Qt5Designer_DEFINITIONS` and related variables may contain generator
expressions that are not compatible with direct `add_definitions()` usage.

This change documents why we continue using `add_definitions()` and
`include_directories()` for Qt5, and relies on target usage requirements
for newer Qt versions instead of failing with a fatal error.
Enable building CTK with either Qt 5 or Qt 6 by updating CMake
configuration and Qt component selection:

* Allow `CTK_QT_VERSION` to be 5 or 6 (defaulting to 6 when `Qt6_DIR`
  is defined, otherwise 5), and validate its value.
* Use common Qt APIs for both Qt 5 and Qt 6 where available
  (e.g. `qt_add_resources`, `qt_create_translation`,
  `qt_wrap_cpp`, plugin setup helpers).
* Add required Qt 6 components when building with Qt 6, including
  `Core5Compat`, `StateMachine`, and `OpenGLWidgets`, while preserving
  existing Qt 5 behavior.
* Restrict use of deprecated or Qt 5–only components:

  * Require `XmlPatterns` only with Qt 5.
  * Force `CTK_USE_QTTESTING` OFF with Qt 6, since QtTesting depends on
    `XmlPatterns`.
  * Disable CommandLine Modules components and applications that depend
    on `XmlPatterns` for Qt 6 builds.
  * Disable DICOM Application Hosting plug-ins and example applications
    that depend on QtSOAP for Qt 6 builds.
* Update core, widgets, VTK widgets, and test CMakeLists to link against
  the appropriate Qt 5/Qt 6 targets based on `CTK_QT_VERSION`.

Co-authored-by: Stefan Dinkelacker <[email protected]>
Co-authored-by: jporcher <[email protected]>
Co-authored-by: Hans Johnson <[email protected]>
- Extend matrix with qt-major-version (5, 6) to exercise both Qt versions.
- Split Qt install into Qt 5 and Qt 6 steps conditioned on qt-major-version.
- Keep using system VTK only for Qt 5 builds; disable it for Qt 6 builds.
- Derive CTK_QT_VERSION from qt-major-version in the configure step.
- Update diagnostic step to print both Qt5_DIR and Qt6_DIR from CMake cache.
@jcfr jcfr merged commit 6781a25 into commontk:master Nov 11, 2025
4 checks passed
@jcfr jcfr deleted the support-qt6 branch November 11, 2025 06:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

When can CTK support qt6.X? Support for Qt >= 6.0

2 participants