I'm doing a small form with Qt, I insert several QPushButton buttons, but I do not have to add the header that specifies it, nor do I add anything in the .cpp or the .h, but it works perfectly. Is the library included in another? In which?
I'm doing a small form with Qt, I insert several QPushButton buttons, but I do not have to add the header that specifies it, nor do I add anything in the .cpp or the .h, but it works perfectly. Is the library included in another? In which?
The graphic classes of Qt can be found in the QtWidgets
library, then any application Qt that has a graphical interface will include this library.
How is it included? Search the project file ( .pro
) and you will find something similar to this:
QT += widgets
This instruction tells the compiler to load the Qt widgets library (note that the non-Qt libraries are loaded completely differently).
Now, if I open the project with QtCreator, I create a form and I put a button in it ... when I execute the code the button appears without me adding any reference How is that possible?
In Qt the forms can have a file ui
that basically is an XML in which the composition of the form is stored. At the time of compiling the application, qmake
generates an MOC from that information, which is nothing more than the source code that generates the detailed composition in ui
... and casually your class Formulario
includes a reference to said MOC . If you check the file * MOC * (you need to compile before) you will see that in this file there are the corresponding includes to the button and to the rest of graphic elements of the form.