Wednesday, July 7, 2010

A simple PushButton to quit

A simple PushButton to quit

#include <QtGui>

int main(int argc, char* argv[])
{
QApplication app(argc, argv);

QWidget* mainwindow = new QWidget();
QPushButton* buttonQuit = new QPushButton("Quit", mainwindow);

QVBoxLayout* mainlayout = new QVBoxLayout();
mainlayout->addWidget(buttonQuit);

QObject::connect(buttonQuit, SIGNAL(clicked()), &app, SLOT(quit()));

mainwindow->setLayout(mainlayout);
mainwindow->show();
return app.exec();
}


This is a qmake-base project start from a Empty Qt Project. All jobs are done in software coding. In the next article "A simple PushButton to quit, built as a Qt Gui Application", it will be shown that how to do the same by starting from a Qt Gui Application.