PDA

View Full Version : Some general questions on Qt



franky
14th July 2019, 15:53
Hello all,

I'm eager to hear from you some simple explanations on the terms below. I know, that there are many great links dealing with those items but they're mostly bewildering for a newbie. If possible, provide me with what you know about them in simple language so that I can completely understand them:

1) What is/are the compiler(s) of Qt when we're writing program on Qt Creator?
2) What are moc, cmake, and qmake?

anda_skoa
15th July 2019, 13:11
1) What is/are the compiler(s) of Qt when we're writing program on Qt Creator?

The most common compilers used with QtCreator are GCC, CLang and MSVC (Microsoft C++ Compiler))



2) What are moc, cmake, and qmake?

MOC is a code generator that reads header files and generates C++ code that contains meta data for things defined in these headers.
For example for QObject based classes this meta data contains the class name, signatures of signals and slot, properties and enums.

CMake and QMake are build systems, the generate instructions on how to build programs.
They can do so across many different compilers and operating systems.

QMake is currently used by Qt for building Qt itself and often used by projects using Qt.

CMake is one of the most often used build systems for C++ applications, whether they are using Qt or not.
Qt will likely switch to using CMake as its main build system with Qt6.

Cheers,
_

franky
15th July 2019, 14:37
thank you very much for your answers.


The most common compilers used with QtCreator are GCC, CLang and MSVC (Microsoft C++ Compiler))

How about MinGW, please?

I'm using Qt 5.12.3. In the Build menu, I have got run qmake also in the Options menu section Build & Run, I have Cmake. What do these mean please?

d_stranz
15th July 2019, 18:59
How about MinGW, please?

MinGW stands for "Minimalist GNU for Windows". It is an implementation of the GNU unix clone that runs in a Windows host OS. By default, MinGW uses the gcc (GNU Compiler Collection) C / C++ compiler.

As anda_skoa explained, cmake is a build system. It is a program that reads a file (CMakeLists.txt) containing a set of commands that describes the source files in your program and other parameters / options needed to build the program, library, or whatever else it is you are trying to build. It writes out either a Makefile (for using "make" with gcc and similar compilers), a similar Makefile file (for using "nmake" with Microsoft C/C++ compiler), or a set of solution (.sln) and project (.vcxproj) files (for Microsoft Visual Studio). cmake can be run from the command line with command line options to specify whether you want to generate Makefiles or build certain targets or configurations within them.

For example, when you use cmake and specify Visual Studio project output files, it will generate a targets called "ALL_BUILD" and "INSTALL", among others. Running cmake to build the ALL_BUILD target will compile and link all of the programs / libraries / whatever that have been defined via the CMakeLists.txt file. Running cmake with the INSTALL target will copy programs / libraries / whatever into the locations you have defined for installation (a bin directory for executables and DLLs, lib directory for link libraries, an include directory for .h files, etc).

qmake is similar. It takes the instructions written in your project's .pro / .pri files and writes out Makefiles appropriate for whatever compiler and linker toolchain you are using. It is generally used in conjunction with Qt Creator, which automates this process through your kit configuration and Build menu, but qmake can be run stand-alone and the Makefiles can be used by the proper build tool (make, nmake) outside of Qt Creator.

If you do not have cmake installed, if the project you are trying to build does not have a CMakeLists.txt file that describes how to build it, and if you don't know how to write one, then you don't want to use cmake. Qt Creator (and other IDEs) contain the tools to build project based on cmake descriptions if that's the way your project is set up.

franky
30th July 2019, 09:32
@anda_skoa

MOC is a code generator that reads header files and generates C++ code that contains meta data for things defined in these headers.
For example for QObject based classes this meta data contains the class name, signatures of signals and slot, properties and enums.
So MOC is actually a bridge between the bass class and derived ones to provide them with the (.cpp) facilities the bass class (.h) offers, right?

@d_stranz
So Cmake/qMake build a makefile for the compiler, in summary. Right?


My compilers are listed below and I also posted my kits. So for Desktop apps I'm now using the MinGW which is naturally GCC and for Android I'm using the CLang compiler.

13210 13211

So my question for this spot is that, I know when my compilers is fetch to work but how should I know what build system is working for my projects? I just hit Run!

d_stranz
30th July 2019, 18:07
So MOC is actually a bridge between the bass class and derived ones to provide them with the (.cpp) facilities the bass class (.h) offers, right?

No, MOC is a code generator that detects the Q_OBJECT macro in a .h file and generates a .cpp file that contains all of the boilerplate code needed to implement what is needed for the Qt Meta-Object system - signals, slots, run-time identification, etc. This cpp file gets compiled and linked into your program along with the .h and .cpp files you have hand-coded for your Qt classes.


So Cmake/qMake build a makefile for the compiler, in summary. Right?

Basically, although cmake is much more powerful than that. cmake can download code from git or another repository, find where the libraries and include files for code that your program uses are installed on your PC, generate build instructions for different platforms and configurations, create an installer, and more.


how should I know what build system is working for my projects?

I don't use Qt Creator very often, but it should be whatever kit(s) you have selected for that project when you configured it. If you hover the mouse over the Debug icon (above Run on my copy of Qt Creator), it will show you the kit it is currently using if you have configured more than one. You can change between kits on the Projects page by clicking on the appropriate tab at the top of the page.