blob: 7360dcafe6821691bbbc01b9a19ec134048493ba [file] [log] [blame]
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the documentation of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:FDL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Free Documentation License Usage
** Alternatively, this file may be used under the terms of the GNU Free
** Documentation License version 1.3 as published by the Free Software
** Foundation and appearing in the file included in the packaging of
** this file. Please review the following information to ensure
** the GNU Free Documentation License version 1.3 requirements
** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
** $QT_END_LICENSE$
**
****************************************************************************/
/*!
\example worldtimeclockbuilder
\ingroup examples-designer
\title World Time Clock Builder Example
\brief Creating forms with Qt Designer that contain custom widgets that can be
dynamically generated at run-time.
\image worldtimeclockbuilder-example.png
This example uses a form containing the custom widget plugin described in the
\l{worldtimeclockplugin}{World Time Clock Plugin} example, and
dynamically generates a user interface using the QUiLoader class, part of
the QtUiTools module.
\section1 Preparation
As with the \l{calculatorbuilder}{Calculator Builder} example, the
project file for this example needs to include the appropriate definitions
to ensure that it is built against the required Qt modules.
\snippet worldtimeclockbuilder/worldtimeclockbuilder.pro 0
By appending \c form to the \c CONFIG declaration, we instruct \c qmake to
generate a dependency on the \c libQtUiTools library containing the QtUiTools
classes.
Note that we do not inform \c qmake about any UI files, and so none will
be processed and built into the application. The resource file contains
an entry for the particular form that we wish to use:
\quotefile worldtimeclockbuilder/worldtimeclockbuilder.qrc
Forms do not need to be included with the application in this way. We only
include a form in the application's resources for convenience, and to keep
the example short.
\section1 Loading and Building the Form
Since this example only loads and displays a pre-prepared form, all of the
work can be done in the main() function. We are using a class from the
QtUiTools library so, in addition to any other Qt classes that are normally
required to write an application, we must include the appropriate header
file:
\snippet worldtimeclockbuilder/main.cpp 0
The main function initializes the resource system with the Q_INIT_RESOURCE()
macro and constructs an QApplication instance in the usual way:
\snippet worldtimeclockbuilder/main.cpp 1
We construct a QUiLoader object to handle the form we want to use.
The form itself is obtained from the resource file system using the path
defined in the resource file. We use the form loader to load and construct
the form:
\snippet worldtimeclockbuilder/main.cpp 2
Once the form has been loaded, the resource file can be closed and the
widget is shown.
\snippet worldtimeclockbuilder/main.cpp 3
The form loader ensures that all the signal and slot connections between
objects in the form are set up correctly when the form is loaded. As a
result, the time is updated by the World Time Clock widget, and the time
zone spin box can be used to change the position of the hour hand.
*/