summaryrefslogtreecommitdiff
path: root/examples/designer/doc/src/calculatorbuilder.qdoc
diff options
context:
space:
mode:
Diffstat (limited to 'examples/designer/doc/src/calculatorbuilder.qdoc')
-rw-r--r--examples/designer/doc/src/calculatorbuilder.qdoc58
1 files changed, 24 insertions, 34 deletions
diff --git a/examples/designer/doc/src/calculatorbuilder.qdoc b/examples/designer/doc/src/calculatorbuilder.qdoc
index a3aaae7be..aae2dece7 100644
--- a/examples/designer/doc/src/calculatorbuilder.qdoc
+++ b/examples/designer/doc/src/calculatorbuilder.qdoc
@@ -25,36 +25,31 @@
\c QtUiTools module library. The project file we use contains all the
necessary information to do this:
- \snippet calculatorbuilder/calculatorbuilder.pro 0
+ \snippet calculatorbuilder/CMakeLists.txt 0
- All the other necessary files are declared as usual.
+ The UI file is loaded from a resource:
- \section1 CalculatorForm Class Definition
+ \snippet calculatorbuilder/CMakeLists.txt 1
- The \c CalculatorForm class defines the widget used to host the form's
- user interface:
+ For \c qmake:
- \snippet calculatorbuilder/calculatorform.h 0
+ \snippet calculatorbuilder/calculatorbuilder.pro 0
- Note that we do not need to include a header file to describe the user
- interface. We only define two public slots, using the auto-connection
- naming convention required by \c uic, and declare private variables
- that we will use to access widgets provided by the form after they are
- constructed.
+ All the other necessary files are declared as usual.
- \section1 CalculatorForm Class Implementation
+ \section1 Loading the Calculator Form
We will need to use the QUiLoader class that is provided by the
\c libQtUiTools library, so we first ensure that we include the header
file for the module:
- \snippet calculatorbuilder/calculatorform.cpp 0
+ \snippet calculatorbuilder/main.cpp 0
- The constructor uses a form loader object to construct the user
- interface that we retrieve, via a QFile object, from the example's
- resources:
+ We create a static helper function that creates a top level
+ widget and loads the user interface that we retrieve,
+ via a QFile object, from the example's resources:
- \snippet calculatorbuilder/calculatorform.cpp 1
+ \snippet calculatorbuilder/main.cpp 1
By including the user interface in the example's resources, we ensure
that it will be present when the example is run. The \c{loader.load()}
@@ -64,32 +59,27 @@
We are interested in three widgets in the generated user interface:
two spin boxes and a label. For convenience, we retrieve pointers to
these widgets from the widget that was constructed by the \c FormBuilder,
- and we record them for later use. The \c qFindChild() template function
+ and we record them for later use. The \c findChild() template function
allows us to query widgets in order to find named child widgets.
- \snippet calculatorbuilder/calculatorform.cpp 2
+ \snippet calculatorbuilder/main.cpp 2
- The widgets created by the form loader need to be connected to the
- specially-named slots in the \c CalculatorForm object. We use Qt's
- meta-object system to enable these connections:
+ The slot that modifies the output widget provided by the form is defined
+ in a similar way to that in the
+ \l{calculatorform}{Calculator Form} example, except that we use a
+ lambda, capturing the widgets found:
- \snippet calculatorbuilder/calculatorform.cpp 3
+ \snippet calculatorbuilder/main.cpp 3
The form widget is added to a layout, and the window title is set:
- \snippet calculatorbuilder/calculatorform.cpp 4
-
- The two slots that modify widgets provided by the form are defined
- in a similar way to those in the \l{calculatorform}{Calculator
- Form} example, except that we read the values from the spin boxes and
- write the result to the output widget via the pointers we recorded in
- the constructor:
-
- \snippet calculatorbuilder/calculatorform.cpp 5
- \codeline
- \snippet calculatorbuilder/calculatorform.cpp 7
+ \snippet calculatorbuilder/main.cpp 4
The advantage of this approach is that we can replace the form when the
application is run, but we can still manipulate the widgets it contains
as long as they are given appropriate names.
+
+ However, loading a form at runtime incurs a runtime cost compared
+ to converting it to C++ code using the \l {User Interface Compiler (uic)}
+ tool.
*/