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
QApplication
in html/qapplication.html in your Qt installation.QFrame
is derived fromQWidget
. Other classes in Qt derived fromQFrame
areQDockWindow
,QGrid
,QGroupBox
,QHBox
,QLCDNumber
,QLabel
,QLineEdit
,QMenuBar
,QPopupMenu
,QProgressBar
,QScrollView
,QSplitter
, andQWidgetStack
.Since
QLabel
inherits fromQFrame
, all public and protected methods ofQFrame
, includingsetFrameStyle()
, are available forQLabel
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”
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.