qApp
A global pointer referring to the unique application object. It is equivalent to the pointer returned by the QCoreApplication::instance() function except that, in GUI applications, it is a pointer to a QApplication instance.
Only one application object can be created.
See also QCoreApplication::instance().
#ifndef MYWIDGET_H
#define MYWIDGET_H #include <QtWidgets/QDialog>
#include "ui_mywidget.h" class mywidget : public QDialog
{
Q_OBJECT public:
mywidget(QWidget *parent = 0);
~mywidget(); private:
Ui::mywidgetClass ui;
}; #endif // MYWIDGET_H #include "mywidget.h"
#include <QtWidgets/QPushButton>
#include <QtWidgets/QApplication>
#include <QFont> mywidget::mywidget(QWidget *parent)
: QDialog(parent)
{
ui.setupUi(this);
setMinimumSize(200, 120);
setMaximumSize(200, 120); QPushButton *quit = new QPushButton("Quit", this);
quit->setGeometry(62, 40, 75, 30);
quit->setFont(QFont("Times", 18, QFont::Bold)); connect(quit, SIGNAL(clicked()), qApp, SLOT(quit()));
} mywidget::~mywidget()
{ }
所以就可以实现单击“Quit”退出