O'Reilly logo

Programming with Qt, 2nd Edition by Matthias Kalle Dalheimer

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Appendix A. Answers to Exercises

Answers to Exercises in Chapter 2

Answers to Exercises in the Section “Hello, world!”

  1. Of course, there is not much to write here. The actual commands to compile Qt applications are indicated in the “Hello, world!” section. Try some of the example programs from the Qt distribution first.

Answers to Exercises in the Section “Using the Qt Reference Documentation”

  1. You can find the documentation for QApplication in html/qapplication.html in your Qt installation.

  2. QFrame is derived from QWidget. Other classes in Qt derived from QFrame are QDockWindow, QGrid, QGroupBox, QHBox, QLCDNumber, QLabel, QLineEdit, QMenuBar, QPopupMenu, QProgressBar, QScrollView, QSplitter, and QWidgetStack.

    Since QLabel inherits from QFrame, all public and protected methods of QFrame, including setFrameStyle(), are available for QLabel objects. You can see all methods available in a class (including those inherited from base classes) in the “List of all member functions” section of the class documentation.

Answers to Exercises in the Section “Adding an Exit Button”

  1. The following code adds another button. There is nothing new here. Note that we have also increased the size of the top-level widget to accommodate the additional widget.

    #include <qapplication.h> #include <qlabel.h> #include <qpushbutton.h> int main( int argc, char* argv[] ) { QApplication myapp( argc, argv ); QWidget* mywidget = new QWidget(); mywidget->setGeometry( 400, 300, 120, 130 ); QPushButton* anotherquitbutton = new ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required