I'm making a small form with Qt, I insert several QPushButton buttons, but I don't have to add the header that specifies it, nor is anything added in the .cpp or .h files, but it works perfectly. Is the library included within another? In which?
I'm making a small form with Qt, I insert several QPushButton buttons, but I don't have to add the header that specifies it, nor is anything added in the .cpp or .h files, but it works perfectly. Is the library included within another? In which?
Qt's graphical classes are found in the library
QtWidgets
, so any Qt application that has a graphical interface will include this library.How is it included? Look in the project file (
.pro
) and you will find something similar to this:This instruction tells the build to load the Qt widget library (note that non-Qt libraries are loaded completely differently).
Now, if I open the project with QtCreator, I create a form and put a button in it... when I execute the code, the button appears without adding any reference. How is it possible?
In Qt, forms can have a file
ui
that is basically an XML in which the composition of the form is stored. When the application is compiled, itqmake
generates a MOC from that information, which is nothing more than the source code that generates the composition detailed in theui
... and your class coincidentallyFormulario
includes a reference to said MOC . If you review the * MOC * file (you need to compile it first) you will see that in said file there are the includes corresponding to the button and the rest of the graphic elements of the form.