Why does Qt use its own make tool, qmake?

C++QtCross PlatformQmake

C++ Problem Overview


I just started using Qt and noticed that it uses its own make tool, qmake.

  • Why does Qt use its own make tool?

  • Is there something special that prevents it from using a standard make tool?

  • Does qmake call the GCC C++ compiler?

C++ Solutions


Solution 1 - C++

Qt uses qmake to transparently support Qt's various addons, including "moc, the meta-object compiler" (which provides signals & slots), "uic, the ui compiler" (which creates header files from .ui designer files), "rcc, the resource compiler" (which compiles resources).

There's nothing to stop you using any build system you want. however, it's a lot more work. For example, you need to run "moc" over every header file that contains a class that has signals or slots. In general it's not recommended, especially for someone who's just starting to use Qt.

QMake does not call g++/gcc directly. Instead, qmake creates native make files on your current platform. Under linux it creates standard GNU make files, under windows it can generate visual studio make files, under Mac OS X it can generate XCode project files. You then invoke your native build system (either GNU make, or MS NMake, or xcodebuild or whatever), which will call your native compiler (g++/gcc or whatever).

Solution 2 - C++

In my opinnion qmake is cool for simple projects (you can just qmake -project; qmake; make), but horrible and not documented enough for largish projects. Especially the configure functionality of qmake is a joke.

The best build systems I know are CMake and Waf (Python -based). In my own Qt-projects I use CMake to do the job. Just like KDE-guys :)

Solution 3 - C++

To support its signal/slot system Qt relies on a special preprocessor and compiler that generates intermediate objects that do much of the processing. They refer to this as the Meta-Object Compiler or MOC.

See Qt 5 Documentation: Using the Meta-Object Compiler for details.

The MOC (along with a couple of other intermediate tools) works in conjunction with qmake; a build automation tool which produces Makefiles in your native format (VC++, g++, etc.) that build the intermediate files generated by the MOC as well as all of your source files into the final executable.

Solution 4 - C++

qmake is designed to be cross platform and flexible. It can compatible with Microsoft Visual Studio and Xcode.

You can find it all in the qmake Manual.

> qmake generates a Makefile based on > the information in a project file. > Project files are created by the > developer, and are usually simple, but > more sophisticated project files can > be created for complex projects. qmake > contains additional features to > support development with Qt, > automatically including build rules > for moc and uic. qmake can also > generate projects for Microsoft Visual > studio without requiring the developer > to change the project file.

Solution 5 - C++

In order

a) because it does lot behind the scenes for you

b) yes, see a)

c) yes, it does call g++ (but can support other compilers if you have them)

Solution 6 - C++

By the way, this was true until Qt 5.x, included. Qt 6 is now switching to CMake instead. At least for building Qt itself, but it seems reasonable to expect that cmake will then be recommended for building Qt applications themselves rather than qmake. Especially since the lead qmake developer no longer work for the Qt Company. Finally an industry-standard tool instead of an in-house one :-)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionTrevor Boyd SmithView Question on Stackoverflow
Solution 1 - C++ThomiView Answer on Stackoverflow
Solution 2 - C++Game CoderView Answer on Stackoverflow
Solution 3 - C++Ron WarholicView Answer on Stackoverflow
Solution 4 - C++Brian GianforcaroView Answer on Stackoverflow
Solution 5 - C++Dirk EddelbuettelView Answer on Stackoverflow
Solution 6 - C++David FaureView Answer on Stackoverflow