summaryrefslogtreecommitdiffstats
path: root/examples/designer/doc/src/calculatorform_mi.qdoc
blob: 7cf0bca160036f4808b9e4e9a21176a50d10db04 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only

/*!
    \example calculatorform_mi
    \examplecategory {Desktop}
    \meta tags {widgets,designer}
    \ingroup examples-designer
    \title Calculator Form/Multiple Inheritance

    \brief Using a form created with \QD in an application.

    The Multiple Inheritance Example shows how to use a form created with
    \l{Qt Widgets Designer} in an application by subclassing both QWidget and the user
    interface class, which is \c{Ui::CalculatorForm}.

    \image calculatorform-example.webp

    To subclass the \c calculatorform.ui file and ensure that \c qmake
    processes it with the \c uic, we have to include \c calculatorform.ui
    in the \c .pro file, as shown below:

    \snippet calculatorform_mi/calculatorform_mi.pro 0

    When the project is compiled, the \c uic will generate a corresponding
    \c ui_calculatorform.h.

    \section1 CalculatorForm Definition

    In the \c CalculatorForm definition, we include the \c ui_calculatorform.h
    that was generated earlier.

    \snippet calculatorform_mi/calculatorform.h 0

    As mentioned earlier, the class is a subclass of both QWidget and
    \c{Ui::CalculatorForm}.

    \snippet calculatorform_mi/calculatorform.h 1

    Two slots are defined according to the \l{Automatic Connections}
    {automatic connection} naming convention required by \c uic. This is
    to ensure that \l{QMetaObject}'s auto-connection facilities connect
    all the signals and slots involved automatically.

    \section1 CalculatorForm Implementation

    In the constructor, we call \c setupUi() to load the user interface file.
    Note that setupUi is a method of \c Ui::CalculatorForm.

    \snippet calculatorform_mi/calculatorform.cpp 0

    We include two slots, \c{on_inputSpinBox1_valueChanged()} and
    \c{on_inputSpinBox2_valueChanged()}. These slots respond to the
    \l{QSpinBox::valueChanged()}{valueChanged()} signal that both spin boxes
    emit. Whenever there is a change in one spin box's value, we take that
    value and add it to whatever value the other spin box has.

    \snippet calculatorform_mi/calculatorform.cpp 1
    \codeline
    \snippet calculatorform_mi/calculatorform.cpp 2

    \section1 \c main() Function

    The \c main() function instantiates QApplication and \c CalculatorForm.
    The \c calculator object is displayed by invoking the \l{QWidget::show()}
    {show()} function.

    \snippet calculatorform_mi/main.cpp 0

    There are various approaches to include forms into applications. The
    Multiple Inheritance approach is just one of them. See
    \l{Using a Designer UI File in Your Application} for more information on
    the other approaches available.
*/