C.3. Chapter 3

C.3.1. Exercises

C.3.1.1. Write a program that shows an empty window. Listing C.5 shows the program.
C.3.1.2. Create a program that shows a window with a button in it. Listing C.6 provides you with this program.

C.3.1.1. Write a program that shows an empty window. Listing C.5 shows the program.

   1 
   2 #include <qwidget.h>
   3 #include <kapp.h>
   4 
   5 
   6 int main(int argc, char **argv)
   7 {
   8   KApplication app(argc, argv);
   9   QWidget window;
  10 
  11   app.setMainWidget(&window);
  12 
  13   window.setGeometry(100,100,200,100);
  14   window.setCaption("Qwidget");
  15   window.show();
  16 
  17   return app.exec();
  18 }
  19 

C.3.1.2. Create a program that shows a window with a button in it. Listing C.6 provides you with this program.

   1 
   2 #include <qwidget.h>
   3 #include <qpushbutton.h>
   4 #include <kapp.h>
   5 
   6 
   7 class MyWindow : public QWidget
   8 {
   9 public:
  10   MyWindow();
  11 };
  12 
  13 MyWindow() : QWidget()
  14 {
  15   QPushButton *button = new QPushButton("Button", this);
  16   button->setGeometry(10,20,100,30);
  17   button->show();
  18 }
  19 
  20 
  21 int main(int argc, char **argv)
  22 {
  23   KApplication app(argc, argv);
  24   MyWindow window;
  25 
  26   app.setMainWidget(&window);
  27 
  28   window.setGeometry(100,100,200,100);
  29   window.setCaption("MyWindow");
  30   window.show();
  31 
  32   return app.exec();
  33 }
  34