Sign up for the KDAB Newsletter
Stay on top of the latest news, publications, events and more.
Go to Sign-up


Find what you need - explore our website and developer resources
14 September 2022
Using CMake you most likely use AUTOMOC. This takes care of running moc on the files which need this.
It does, however, come with one drawback, namely that all moc files are compile together, which means that touching any header with a Q_OBJECT in it results in lots and lots of code being recompiled.
By including the moc files in the .cpp files I went from 22 seconds to 5 seconds when recompiling after touching a simple header file.
This episode comes with a script to automate this plus a git hook to ensure you always remember to include the moc files.
Links:
* The source code: https://github.com/KDAB/KDToolBox/tree/master/qt/includemocs
* CMake's AUTOMOC https://cmake.org/cmake/help/v3.9/prop_tgt/AUTOMOC.html
* My episodes on git hooks: https://www.youtube.com/watch?v=CrkxCDv8RIo
0:00 Intro
0:18 What does moc do?
0:51 Details of all the steps when compiling using QMake
2:12 The core of the problem with QMake
2:49 Details for compiling using CMake
5:29 So why does CMake need to recompile the moc files?
6:11 What is the solution?
8:30 But I am already including moc_filename.cpp files....
9:59 The script to help you
10:43 Running the script
13:30 Outro
All QML tips and tricks videos : https://www.youtube.com/playlist?list=PL6CJYn40gN6jWHP5krsQrVGyYtKh3A3be
All Qt Widgets and more videos:
https://www.youtube.com/playlist?list=PL6CJYn40gN6gf-G-o6syFwGrtq3kItEqI
Stay on top of the latest news, publications, events and more.
Go to Sign-up
Learn Modern C++
Our hands-on Modern C++ training courses are designed to quickly familiarize newcomers with the language. They also update professional C++ developers on the latest changes in the language and standard library introduced in recent C++ editions.
Learn more