Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 21st, 2012  |  syntax: C++  |  size: 1.44 KB  |  hits: 19  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include <QtGui>
  2. int main(int argv, char **args){
  3.     class Notepad: public QWidget{
  4.         //Q_OBJECT
  5.     public:
  6.         Notepad();
  7.     private slots:
  8.         void quit();
  9.     private:
  10.         QTextEdit *textEdit;
  11.         QPushButton *quitButton;
  12.     };
  13.     Notepad::Notepad()
  14.     {
  15.         textEdit = new QTextEdit;
  16.         quitButton = new QPushButton(tr("Quit"));
  17.         connect(quitButton, SIGNAL(clicked()), this, SLOT(quit()));
  18.         QVBoxLayout *layout = new QVBoxLayout;
  19.         layout -> addWidget(textEdit);
  20.         layout -> addWidget(quitButton);
  21.         setLayout(layout);
  22.         setWindowTitle(tr("Notepad"));
  23.     }
  24.     void Notepad::quit(){
  25.         QMessageBox messageBox;
  26.         messageBox.setWindowTitle(tr("Notepad"));
  27.         messageBox.setText(tr("Do you really want to quit?"));
  28.         messageBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
  29.         messageBox.setDefaultButton(QMessageBox::No);
  30.         if (messageBox.exec() == QMessageBox::Yes)
  31.             qApp->quit();
  32.     }
  33.     QApplication app(argv, args);
  34.     QTextEdit *textEdit = new QTextEdit;
  35.     QPushButton *quitButton = new QPushButton("&Quit");
  36.     QObject::connect(quitButton, SIGNAL(clicked()), qApp, SLOT(quit()));
  37.     QVBoxLayout *layout = new QVBoxLayout;
  38.     layout->addWidget(textEdit);
  39.     layout->addWidget(quitButton);
  40.     QWidget window;
  41.     window.setLayout(layout);
  42.     window.show();
  43.     return app.exec();
  44. }