Update copyright headers
[qt:qt.git] / doc / src / examples / multipleinheritance.qdoc
1 /****************************************************************************
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
5 **
6 ** This file is part of the documentation of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:FDL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see http://www.qt.io/terms-conditions. For further
15 ** information use the contact form at http://www.qt.io/contact-us.
16 **
17 ** GNU Free Documentation License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Free
19 ** Documentation License version 1.3 as published by the Free Software
20 ** Foundation and appearing in the file included in the packaging of
21 ** this file.  Please review the following information to ensure
22 ** the GNU Free Documentation License version 1.3 requirements
23 ** will be met: http://www.gnu.org/copyleft/fdl.html.
24 ** $QT_END_LICENSE$
25 **
26 ****************************************************************************/
27
28 /*!
29     \example uitools/multipleinheritance
30     \title Multiple Inheritance Example
31
32     \brief The Multiple Inheritance Example shows how to use a form created with \QD
33     in an application by subclassing both QWidget and the user interface
34     class, which is \c{Ui::CalculatorForm}.
35
36     \image multipleinheritance-example.png
37
38     To subclass the \c calculatorform.ui file and ensure that \c qmake
39     processes it with the \c uic, we have to include \c calculatorform.ui
40     in the \c .pro file, as shown below:
41
42     \snippet examples/uitools/multipleinheritance/multipleinheritance.pro 0
43
44     When the project is compiled, the \c uic will generate a corresponding
45     \c ui_calculatorform.h.
46
47     \section1 CalculatorForm Definition
48
49     In the \c CalculatorForm definition, we include the \c ui_calculatorform.h
50     that was generated earlier.
51
52     \snippet examples/uitools/multipleinheritance/calculatorform.h 0
53
54     As mentioned earlier, the class is a subclass of both QWidget and
55     \c{Ui::CalculatorForm}.
56
57     \snippet examples/uitools/multipleinheritance/calculatorform.h 1
58
59     Two slots are defined according to the \l{Automatic Connections}
60     {automatic connection} naming convention required by \c uic. This is
61     to ensure that \l{QMetaObject}'s auto-connection facilities connect
62     all the signals and slots involved automatically.
63
64     \section1 CalculatorForm Implementation
65
66     In the constructor, we call \c setupUi() to load the user interface file.
67     Note that we do not need the \c{ui} prefix as \c CalculatorForm is a
68     subclass of the user interface class.
69
70     \snippet examples/uitools/multipleinheritance/calculatorform.cpp 0
71
72     We include two slots, \c{on_inputSpinBox1_valueChanged()} and
73     \c{on_inputSpinBox2_valueChanged()}. These slots respond to the
74     \l{QSpinBox::valueChanged()}{valueChanged()} signal that both spin boxes
75     emit. Whenever there is a change in one spin box's value, we take that
76     value and add it to whatever value the other spin box has.
77
78     \snippet examples/uitools/multipleinheritance/calculatorform.cpp 1
79     \codeline
80     \snippet examples/uitools/multipleinheritance/calculatorform.cpp 2
81
82     \section1 \c main() Function
83
84     The \c main() function instantiates QApplication and \c CalculatorForm.
85     The \c calculator object is displayed by invoking the \l{QWidget::show()}
86     {show()} function.
87
88     \snippet examples/uitools/multipleinheritance/main.cpp 0
89
90     There are various approaches to include forms into applications. The
91     Multiple Inheritance approach is just one of them. See
92     \l{Using a Designer UI File in Your Application} for more information on
93     the other approaches available.
94 */