// Creating a main window QMainWindow window; // ... code to add widgets and layout ... // Closing the window when button is clicked QPushButton button("Close"); QObject::connect(&button, SIGNAL(clicked()), &window, SLOT(close()));
// Creating a dialog box QDialog dialog; // ... code to add widgets and layout ... // Closing the dialog box when button is clicked QPushButton button("Close"); QObject::connect(&button, SIGNAL(clicked()), &dialog, SLOT(close()));In this example, a QDialog box is created, and a QPushButton widget is added to it. The signal from the button clicked is connected to the close() slot of the dialog, resulting in the dialog box being closed when the button is clicked. Package/Library: Qt