diff options
author | Lars Knoll <lars.knoll@nokia.com> | 2009-03-23 09:18:55 (GMT) |
---|---|---|
committer | Simon Hausmann <simon.hausmann@nokia.com> | 2009-03-23 09:18:55 (GMT) |
commit | e5fcad302d86d316390c6b0f62759a067313e8a9 (patch) | |
tree | c2afbf6f1066b6ce261f14341cf6d310e5595bc1 /doc/src/examples/calculatorform.qdoc | |
download | Qt-e5fcad302d86d316390c6b0f62759a067313e8a9.zip Qt-e5fcad302d86d316390c6b0f62759a067313e8a9.tar.gz Qt-e5fcad302d86d316390c6b0f62759a067313e8a9.tar.bz2 |
Long live Qt 4.5!
Diffstat (limited to 'doc/src/examples/calculatorform.qdoc')
-rw-r--r-- | doc/src/examples/calculatorform.qdoc | 126 |
1 files changed, 126 insertions, 0 deletions
diff --git a/doc/src/examples/calculatorform.qdoc b/doc/src/examples/calculatorform.qdoc new file mode 100644 index 0000000..a8e891e --- /dev/null +++ b/doc/src/examples/calculatorform.qdoc @@ -0,0 +1,126 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \example designer/calculatorform + \title Calculator Form Example + + The Calculator Form Example shows how to use a form created with + \QD in an application by using the user interface information from + a QWidget subclass. We use \l{Using a Designer .ui File in Your Application} + {uic's auto-connection} feature to automatically connect signals + from widgets on the form to slots in our code. + + \image calculatorform-example.png Screenshot of the Calculator Form example + + The example presents two spin boxes that are used to input integer values + and a label that shows their sum. Whenever either of the spin boxes are + updated, the signal-slot connections between the widgets and the form + ensure that the label is also updated. + + \section1 Preparation + + The user interface for this example is designed completely using \QD. The + result is a .ui file describing the form, the widgets used, any signal-slot + connections between them, and other standard user interface properties. + + To ensure that the example can use this file, we need to include a \c FORMS + declaration in the example's project file: + + \snippet examples/designer/calculatorform/calculatorform.pro 1 + + When the project is built, \c uic will create a header file that lets us + construct the form. + + \section1 CalculatorForm Class Definition + + The \c CalculatorForm class uses the user interface described in the + \c calculatorform.ui file. To access the form and its contents, we need + to include the \c ui_calculatorform.h header file created by \c uic + during the build process: + + \snippet examples/designer/calculatorform/calculatorform.h 0 + + We define the \c CalculatorForm class by subclassing QWidget because the + form itself is based on QWidget: + + \snippet examples/designer/calculatorform/calculatorform.h 1 + + Apart from the constructor, the class contains two private slots that + are named according to the auto-connection naming convention required + by \c uic. + The private \c ui member variable refers to the form, and is used to + access the contents of the user interface. + + \section1 CalculatorForm Class Implementation + + The constructor simply calls the base class's constructor and + sets up the form's user interface. + + \snippet examples/designer/calculatorform/calculatorform.cpp 0 + + The user interface is set up with the \c setupUI() function. We pass + \c this as the argument to this function to use the \c CalculatorForm + widget itself as the container for the user interface. + + To automatically connect signals from the spin boxes defined in the + user interface, we use the naming convention that indicates which + widgets and their signals in the user interface should be connected + to each slot. The first slot is called whenever the spin box called + "inputSpinBox1" in the user interface emits the + \l{QSpinBox::valueChanged()}{valueChanged()} signal: + + \snippet examples/designer/calculatorform/calculatorform.cpp 1 + + When this occurs, we use the value supplied by the signal to update the + output label by setting its new text directly. We access the output label + and the other spin box via the class's private \c ui variable. + + The second slot is called whenever the second spin box, called + "inputSpinBox2", emits the \l{QSpinBox::valueChanged()}{valueChanged()} + signal: + + \snippet examples/designer/calculatorform/calculatorform.cpp 2 + + In this case, the value from the first spin box is read and combined + with the value supplied by the signal. Again, the output label is + updated directly via the \c ui variable. +*/ |