56

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?
Trojan
  • 2,208
  • 26
  • 40
Trevor Boyd Smith
  • 15,512
  • 24
  • 110
  • 159
  • 24
    you misunderstand, `qmake` is more of a replacement for `configure`, not `make` – Evan Teran Sep 02 '09 at 16:58
  • 1
    If you're familiar with Imakefiles, your qt .pro file is a replacement for that. Instead of making a Makefile out of your Imakefile, qmake makes a Makefile out of your .pro file. (It can also generate the .pro file for you, though you will sometimes need to add to its defaults.) – Bill Jan 25 '10 at 22:45

6 Answers6

58

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).

Thomi
  • 11,159
  • 9
  • 67
  • 109
  • RE "QMake does not call g++/gcc directly": So QT doesn't use a standard C++ compiler like gcc? What compiler does it use? – Trevor Boyd Smith Sep 02 '09 at 16:14
  • QT is cross platform; it can be compiled with many different compilers. – Ron Warholic Sep 02 '09 at 16:20
  • 8
    QMake DOES NOT call gcc directly. It creates platform-specific make files that *you* then invoke. These make files in turn call whatever compiler you seem to be using. – Thomi Sep 03 '09 at 07:21
  • @Trevor, QMake simply generates makefiles and other build projects for different systems, like GNU makefiles, VC++ or XCode projects, NMake makefile, and so on. – CMircea May 05 '10 at 15:03
  • 1
    I think it's worth mentioning that there are other tools besides qmake that also do all this work for you (namely [cmake](https://cmake.org/)). – Matthias Kuhn Jun 05 '16 at 16:46
9

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 :)

Game Coder
  • 107
  • 1
  • 2
6

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.

Ron Warholic
  • 9,744
  • 27
  • 47
5

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.

Brian Gianforcaro
  • 24,434
  • 11
  • 53
  • 76
3

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)

Dirk Eddelbuettel
  • 331,520
  • 51
  • 596
  • 675
1

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 :-)

David Faure
  • 1,363
  • 11
  • 14
  • You can read more at https://www.kdab.com/qt-and-cmake/ for instance – David Faure Jun 13 '20 at 21:59
  • `qbs` has been discontinued, you can read more at https://www.qt.io/blog/2018/10/29/deprecation-of-qbs – David Faure Jun 13 '20 at 22:00
  • I'm glad to hear that Qt has decided to stop using their very limited resources on creating another build system when there are already 1000 other build systems: see https://xkcd.com/927/ . – Trevor Boyd Smith Jun 16 '20 at 12:19