-
Notifications
You must be signed in to change notification settings - Fork 643
COMP: Enable automoc for qt wrapping #8568
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
6
commits into
main
Choose a base branch
from
enable-automoc-for-qt-wrapping
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
2757408
to
6b9fe7c
Compare
@jcfr failures are due to SurfaceToolbox
|
6b9fe7c
to
7837918
Compare
411eb4a
to
393b8fc
Compare
393b8fc
to
463c8a3
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.
Need synchronize with SlicerSurfaceToolbox to include support for finding .ui files with AUTOMOC.
463c8a3
to
9e65669
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.
ENH: Initial code changes to support qt5.15 and qt6
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 the 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).
This triggered conversion to AUTOMOC instead of trying to figure out
the necessary wrapping that would have been needed to support the
new Q_OBJECT infrastructures..
DEPENDS ON:
- ENH: Prepare for Qt6 build with AUTOMOC support SlicerSurfaceToolbox#79
COMP: Fix Qt linkage requirements
COMP: Add support for Qt5 & Qt6 signal/slot syntax
ENH: Enable Qt auto-tools in preparation for Qt6 compatibility
COMP: Change include for AUTOMOC naming conventions
COMP: Replace explicit Qt5 macros with CMake auto-tooling
COMP: Fix AUTOMOC for SlicerSurfaceToolbox
Prepares for FUTURE CHANGES FOR UPDATING CTK: