r/cpp • u/Kelteseth arewemodulesyet.org • Sep 07 '26
Qt moc now can handle basic C++ modules (Qt 6.12)
https://codereview.qt-project.org/c/qt/qtbase/+/757821moc: Properly handle modules
When moc'ing module interfaces and partitions, we make the generated cpp
file part of the respective module.
We do not support Q_OBJECT & friends in implementation units and private
module fragments, as our generated source file will not have access to
the respective classes, and we certainly do not want to carry over our
file inclusion hacks into the module world.
[ChangeLog][moc] moc now supports C++ modulesmoc: Properly handle modulesNote there is still a lot of work to be done: https://codereview.qt-project.org/c/qt/qtbase/+/767846 and I can't seem to find the PR where they fixed some qtbase code to make it work with modules. I guess most other qt modules will need some small fixes to work with modules as well.
67
Upvotes
16
u/abbapoh Qbs dev Sep 07 '26
> I can't seem to find the PR where they fixed some qtbase code
Modules has been tested with a QtCreator as proof-of-concept, currently there are no plans on adding modules support to qtbase afaik.
https://codereview.qt-project.org/c/qt-creator/qt-creator/+/755635
We also back-ported the Moc machinery to Qbs, so modules should work with older Qt versions too with Qbs.
https://codereview.qt-project.org/c/qbs/qbs/+/758007
This can probably could be done with CMake too, although it requires knowing includes in order to properly patch the file.
7
u/meetingcpp Meeting C++ | C++ Evangelist Sep 07 '26
What about templates?
4
u/current_thread Sep 07 '26
Ha! And I started a small qt project yesterday and was about to use modules. That's excellent news!
9
u/Ok_Independence_9841 Sep 07 '26
This is nice and all but honestly I've had class meta data and multi threaded, multi library, signals and slots working, cleanly and easily, in native C++, without moc, for many years. Copper Spice solved 95% or this in C++11. It's long past time Qt dropped the pre-compiler. Or at least seriously re-assessed whether it's adding any value.
The old article they used to point at that claimed you couldn't do signals and slots properly without it was dubious 15 years ago. It's junk now. I worked in a Qt shop with ex Nokia people who toiled on their failed port to a new mobile OS so I'm pretty familiar with how Qt works. It's a great framework that would be better without moc.