| 1 | /**************************************************************************** | 
|---|
| 2 | ** | 
|---|
| 3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). | 
|---|
| 4 | ** All rights reserved. | 
|---|
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com) | 
|---|
| 6 | ** | 
|---|
| 7 | ** This file is part of the documentation of the Qt Toolkit. | 
|---|
| 8 | ** | 
|---|
| 9 | ** $QT_BEGIN_LICENSE:FDL$ | 
|---|
| 10 | ** Commercial Usage | 
|---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in | 
|---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the | 
|---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in a | 
|---|
| 14 | ** written agreement between you and Nokia. | 
|---|
| 15 | ** | 
|---|
| 16 | ** GNU Free Documentation License | 
|---|
| 17 | ** Alternatively, this file may be used under the terms of the GNU Free | 
|---|
| 18 | ** Documentation License version 1.3 as published by the Free Software | 
|---|
| 19 | ** Foundation and appearing in the file included in the packaging of this | 
|---|
| 20 | ** file. | 
|---|
| 21 | ** | 
|---|
| 22 | ** If you have questions regarding the use of this file, please contact | 
|---|
| 23 | ** Nokia at qt-info@nokia.com. | 
|---|
| 24 | ** $QT_END_LICENSE$ | 
|---|
| 25 | ** | 
|---|
| 26 | ****************************************************************************/ | 
|---|
| 27 |  | 
|---|
| 28 | /*! | 
|---|
| 29 | \example uitools/multipleinheritance | 
|---|
| 30 | \title Multiple Inheritance Example | 
|---|
| 31 |  | 
|---|
| 32 | 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 | */ | 
|---|