-
Notifications
You must be signed in to change notification settings - Fork 674
DRAFT: Clazy qt6/qt5 recommended fixes #8543
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
hjmjohnson
wants to merge
12
commits into
Slicer:main
Choose a base branch
from
hjmjohnson:clazy-qt6-auto-fixes
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bec7e01 to
b2eda11
Compare
b2eda11 to
b2226af
Compare
b2226af to
6560581
Compare
Classes derived from Q_OBJECT can not be declared/defined
in an anonymous namespace because it affects qt's moc
to generate the neccessary items needed for linkage.
In Qt, when a class has the Q_OBJECT macro, it requires moc (Meta-Object
Compiler) to generate code implementing functions like:
• metaObject() const
• qt_metacast()
• qt_metacall()
• signal/slot dispatch code
If moc is not run, or the result is not compiled/linked,
you’ll get linker errors like the one above.
----
Followup fixes needed:
Even though event is declared as a QEvent*, the compiler cannot
guarantee that it actually points to a QMouseEvent. The classes aren’t
related through inheritance in a static type-safe way.
Casting across siblings in the event class hierarchy is invalid.
Use dynamic_cast<> for casting between heirchies that do *not*
derive from QObject (i.e. QEvents do not derive from QObjects)
Use qobject_cast<> for casting between QObjects.
Qt provides qobject_cast<T*>(QObject*) as a safe way to cast between
QObject-derived types using Qt’s meta-object system (requires Q_OBJECT
in the class). It is RTTI‑free, works across shared libraries, and
is available in both Qt 5 and Qt 6  .
• The function is declared in qobject.h, which is indirectly
included by <QObject> in both Qt versions
Add missing Q_OBJECT to complete Qt inheritance best practices The Q_OBJECT macro is mandatory for any class that: • Inherits from QObject • Uses signals or slots • Declares properties (Q_PROPERTY) • Needs qobject_cast, metaObject(), or other Qt RTTI features Without it: • Qt’s meta-object compiler (moc) won’t generate necessary code • You may encounter runtime errors or silently broken signals/slots • Clazy and Qt's build system may warn or fail These best practices deficiencies were identified and auto-fixed with the clazy tool (Qt adaptation of the clang-tidy tools).
Preparing for Qt6 where the CMakeified auto-tooling is preferred over the explicit wrapping.
The manual QT5 wrapping macros used moc_{class}.cxx for naming
of autogenerated files. AUTOMOC uses {class}.moc as the
naming for the the autogenerated files.
Adding missing {class}.moc includes for the AUTOMOC behaviors.
Refactored CMakeLists to utilize lists and definitions for MOC and resource files instead of explicit `QT5_WRAP_CPP`, `QT5_WRAP_UI`, and `QT5_GENERATE_MOCS`. This change improves compatibility with both Qt5 and Qt6 by adhering to modern CMake standards.
Depends upon: Slicer/SlicerSurfaceToolbox#79 Need synchronize with SlicerSurfaceToolbox to include support for finding .ui files with AUTOMOC.
Clazy can automatically fix many Qt5-to-Qt6 porting issues using Fix‑It style rewrites—but with some important caveats. Here’s how it works: Clazy includes several Qt6‑porting checks that provide automatic fix-it suggestions, including: • qt6-deprecated-api-fixes • qt6-header-fixes • qt6-qhash-signature • qt6-fwd-fixes • missing-qobject-macro  These checks can identify deprecated APIs and even offer automatic replacements. Clazy generates .clazy.yaml files alongside your source files, containing replacement instructions. • Use clang-apply-replacements <path> to apply changes in bulk. • Conflicts or ambiguous fix‑its are reported and halted.⚠️ Limitations and Notes • Not all Qt6 migration issues can be auto-fixed. Some require manual review. • Fix‑its may conflict if multiple rules apply to the same code line. Handle with caution. • After applying fixes, your code may only compile under Qt6, not with Qt5. Use git diff tools to add pre-processor alternate compilations paths to support both Qt5 and Qt6 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) menuOption.tabWidth = 0; #endif
Signals for view properties in qMRMLAbstractViewWidget Added `viewLabelChanged` and `viewColorChanged` signals and updated Q_PROPERTY macros with NOTIFY to enable property change notifications.
Signals for view properties in qMRMLAbstractViewWidget Added `viewLabelChanged` and `viewColorChanged` signals and updated Q_PROPERTY macros with NOTIFY to enable property change notifications.
6560581 to
ae6cd60
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Work is being done to address Qt6 upgrade preparations by using the
clazycompilation to expose recommended updates.THIS PR IS NOT INTENDED TO BE MERGED. Items identified during this process should be "cherry-picked" and incorporated independently of this PR.
In many cases, small commits will be able to be re-arranged and merged, then cherry-picked to separate topics for merging.