// hello.h #include <qwidget.h> #include <qpushbutton.h> #include <qlayout.h> #include <qapplication.h> class Hello: public QWidget { Q_OBJECT public: Hello(); private: QPushButton *button1; private slots: void callback1(); }; | // hello.cpp #include "hello.h" Hello::Hello(): QWidget( 0, 0 ) { button1 = new QPushButton("button1", this ); connect(button1, SIGNAL(clicked()), this, SLOT(callback1()) ); QVBoxLayout *main = new QVBoxLayout(this); main->addWidget(button1); main->setMargin(5); } void Hello::callback1() { button1->setText("clicked"); } int main( int argc, char **argv ) { QApplication a( argc, argv ); Hello t; a.setMainWidget(&t); t.show(); return a.exec(); } |