Skip to content

ENH: Restore CTK_USE_QTTESTING support for Qt 6 (#1314) - #1379

Merged
jamesobutler merged 7 commits into
commontk:masterfrom
BRAINSia:fix/issue-1314
Mar 28, 2026
Merged

ENH: Restore CTK_USE_QTTESTING support for Qt 6 (#1314)#1379
jamesobutler merged 7 commits into
commontk:masterfrom
BRAINSia:fix/issue-1314

Conversation

@hjmjohnson

@hjmjohnson hjmjohnson commented Mar 28, 2026

Copy link
Copy Markdown
Contributor

Summary

Resolves #1314. CTK_USE_QTTESTING was forcibly disabled for Qt 6 builds because ctkXMLEventSource depended on Qt XmlPatterns, which is unavailable in Qt 6. This PR removes that restriction through a series of targeted, independent fixes.

Commits

Commit Change
COMP: Set CMAKE_CXX_STANDARD for Qt support Require C++17 in CTK's top-level CMakeLists (recommended for Qt 5.15, required for Qt 6)
ENH: Update QtTesting with Qt 6 support Update from the stale 2019 pin to latest master branch which includes Qt 6 CMake support, int() casts for QFlags→QString::arg() (Qt 6.11 removed implicit conversion), and C++17 enforcement in QtTesting's CMakeLists.
ENH: Allow CTK_USE_QTTESTING=ON with Qt 6 builds Remove the block in CMakeLists.txt that forced CTK_USE_QTTESTING=OFF for Qt 6
COMP: Guard ctkXMLEventSource XmlPatterns usage for Qt 6 Wrap QXmlSchema/QXmlSchemaValidator includes and usage behind #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) — the rest of the file (QXmlStreamReader) is Qt 6 compatible
COMP: Guard Qt5::XmlPatterns link dependency for Qt 6 builds Guard the Qt5::XmlPatterns entry in Libs/QtTesting/CMakeLists.txt so it is only added for Qt 5 builds
COMP: Detect both QtTesting and qttesting CMake target names The upstream target name changed from QtTesting (pre-2024) to qttesting (lowercase) in newer revisions; add if(TARGET qttesting) checks in Libs/QtTesting, Libs/Widgets, and Libs/Visualization/VTK/Widgets
COMP: Fix ctkVTKRenderViewEventTranslator for Qt 6 (protected operator=) QInputEvent::operator= is protected in Qt 6, making QMouseEvent value members non-assignable; change to std::optional<QMouseEvent> and use .emplace() for in-place construction
BUG: Replace QRegExp with QRegularExpression in ITK logging test QRegExp was removed in Qt 6; replace with QRegularExpression and update exactMatch()regexp.match(...).hasMatch()

Verification

Qt 6.11.0 build verified on macOS ARM64 with CTK_USE_QTTESTING=ON: libCTKQtTesting.dylib builds and links successfully.

Test plan

  • Qt 5 build with CTK_USE_QTTESTING=ON: confirm no regressions
  • Qt 6 build with CTK_USE_QTTESTING=ON: confirm QtTesting builds and links successfully
  • Qt 6.11.0 build verified locally on macOS ARM64

@hjmjohnson
hjmjohnson marked this pull request as draft March 28, 2026 13:33
Comment thread CMakeExternals/QtTesting.cmake Outdated
@hjmjohnson
hjmjohnson force-pushed the fix/issue-1314 branch 2 times, most recently from 5556696 to 45ef4bd Compare March 28, 2026 15:35
@hjmjohnson
hjmjohnson marked this pull request as ready for review March 28, 2026 15:36
@hjmjohnson
hjmjohnson force-pushed the fix/issue-1314 branch 2 times, most recently from 8a46811 to f872a59 Compare March 28, 2026 17:02
@jamesobutler

Copy link
Copy Markdown
Contributor

@hjmjohnson Some minor merge conflicts to resolve post-QRegularExpression update

@jamesobutler

jamesobutler commented Mar 28, 2026

Copy link
Copy Markdown
Contributor

I wasn't allowed to push to BRAINSia:fix/issue-1314 otherwise I would have fixed the merge conflicts by dropping the BUG: Replace QRegExp with QRegularExpression in ITK logging test since b76d5d4 was integrated.

C++17 is highly recommended for Qt5.15 and is
required for Qt6.
(ctk-2026-03-27), which includes:
  - Qt 6 CMake support from commontk HEAD (4bdc580)
  - QFlags int() casts for Qt 6.11 QString::arg() compatibility
    (implicit QFlags→int conversion was removed in Qt 6.11)
  - C++17 standard enforcement in QtTesting CMakeLists
Remove the block that forced CTK_USE_QTTESTING=OFF when building with
Qt 6. The QtXmlPatterns dependency that prevented Qt 6 support has been
isolated to ctkXMLEventSource (addressed separately), so CTK_USE_QTTESTING
can now be enabled for Qt 6 users.
The upstream QtTesting target name changed from "QtTesting" (pre-2024)
to lowercase "qttesting" in newer revisions. Add an if(TARGET qttesting)
check in Libs/QtTesting, Libs/Widgets, and Libs/Visualization/VTK/Widgets
so both the old Qt5 pin and the new Qt6-compatible revision link correctly.

Changes suggested by AI coding tools
QXmlSchema and QXmlSchemaValidator are from the QtXmlPatterns module
which does not exist in Qt 6. Guard their includes and usage behind
\#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0). The rest of the file
(QXmlStreamReader) is already Qt 6 compatible.
Qt 6 removed the XmlPatterns module. Guard the Qt5::XmlPatterns
target_link_libraries entry so it is only added for Qt 5 builds.
ctkXMLEventSource already guards its XmlPatterns usage at the source level.

Changes suggested by AI coding agent
QInputEvent::operator= is protected in Qt 6, making QMouseEvent members
non-assignable. Change lastMoveEvent, oldMoveEvent, and lastMouseEvent
from QMouseEvent value members to std::optional<QMouseEvent> so that
.emplace() can be used for in-place construction instead of copy-assign.
Update all access sites to use -> dereference.

Changes suggested by AI coding tools
@jamesobutler
jamesobutler enabled auto-merge (rebase) March 28, 2026 20:21
@jamesobutler
jamesobutler merged commit 4322592 into commontk:master Mar 28, 2026
4 checks passed
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.

Restore CTK_USE_QTTESTING support with Qt 6

2 participants