Widgets are visual GUI components. If a widget doesn't have a parent, it is treated as a window, otherwise known as a top-level widget. Earlier in this chapter, we created the simplest possible window in Qt, as shown in the following code:
#include <QtWidgets>
int main(int argc, char** argv)
{
QApplication app(argc, argv);
QWidget window;
window.resize(120, 100);
window.setWindowTitle("Mastering C++");
window.show();
return app.exec();
}
As you can see, the window object doesn't have a parent. The thing is, the constructor of QWidget takes another QWidget as the parent of the current one. So, when we declare a button and want it to be a child of our window object, we do so in the following way:
#include <QtWidgets>
int main(int argc, char** argv)
{
QApplication app(argc, argv);
QWidget window;
window.resize(120, 100);
window...