Appendix A. Answers to Exercises
Answers to Exercises in Chapter 2
Answers to Exercises in the Section “Hello, world!”
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”
You can find the documentation for
QApplicationin html/qapplication.html in your Qt installation.QFrameis derived fromQWidget. Other classes in Qt derived fromQFrameareQDockWindow,QGrid,QGroupBox,QHBox,QLCDNumber,QLabel,QLineEdit,QMenuBar,QPopupMenu,QProgressBar,QScrollView,QSplitter, andQWidgetStack.Since
QLabelinherits fromQFrame, all public and protected methods ofQFrame, includingsetFrameStyle(), are available forQLabelobjects. 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”
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 ...