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 ...

Get Programming with Qt, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.