#include "mainwindow.h"#include <QApplication>#include <QtGui>#include <QStackedWidget>#include <QPushButton>#include <QWidget>#include <QGroupBox>#include <QLayout>#include <QObject>#include <QtDebug>class MainWidget : public QWidget { public : QPushButton* buttonRules; MainWidget( );};class RulesWidget : public QWidget { public: QPushButton* mainButton; RulesWidget();};MainWidget :: MainWidget () { buttonRules = new QPushButton("Rules"); QVBoxLayout* buttonLayout = new QVBoxLayout; buttonLayout->addWidget(buttonRules); setLayout(buttonLayout);}RulesWidget :: RulesWidget () { mainButton = new QPushButton("Main"); QVBoxLayout* buttonLayout = new QVBoxLayout; buttonLayout->addWidget(mainButton); setLayout(buttonLayout);}class TheMainestWidget : public QWidget { private: public: MainWidget* menu; RulesWidget* rules; QStackedWidget* stackOfWidgets; TheMainestWidget (); public slots: void clickMenu (QStackedWidget*); void clickRules ();};TheMainestWidget :: TheMainestWidget () { menu = new MainWidget; rules = new RulesWidget; stackOfWidgets = new QStackedWidget; stackOfWidgets->addWidget(menu); stackOfWidgets->addWidget(rules); stackOfWidgets->setCurrentWidget(menu); // stackOfWidgets->show(); connect(rules->mainButton, SIGNAL(clicked()), qApp, SLOT(quit())); connect(menu->buttonRules, SIGNAL(clicked()), SLOT(clickRules () )); stackOfWidgets->show();}void TheMainestWidget :: clickMenu(QStackedWidget* stackOfWidgets) { stackOfWidgets->setCurrentWidget(menu); stackOfWidgets->show();}void TheMainestWidget :: clickRules() { stackOfWidgets->setCurrentWidget(rules); stackOfWidgets->show();}int main(int argc, char *argv[]) { QApplication a(argc, argv); // MainWindow w; // w.show(); TheMainestWidget game; return a.exec();}
TheMainestWidget :: TheMainestWidget (QApplication &a)
QApplication &a
C++ (Qt)connect( rules->mainButton, SIGNAL(clicked()), qApp , SLOT(quit())) ;