1// Copyright (C) 2017 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
5 \page qtquickcontrols-gettingstarted.html
6 \keyword Getting Started with Qt Quick Controls 2
7 \title Getting Started with Qt Quick Controls
9 A basic example of a QML file that makes use of controls is shown here:
13 import QtQuick.Controls
16 title: "My Application"
23 anchors.centerIn: parent
28 \section1 Setting Up Controls from C++
30 Although QQuickView has traditionally been used to display QML files in a
31 C++ application, doing this means you can only set window properties from
34 With Qt Quick Controls, declare an ApplicationWindow as the root item of
35 your application and launch it by using QQmlApplicationEngine instead.
36 This ensures that you can control top level window properties from QML.
38 A basic example of a source file that makes use of controls is shown here:
41 #include <QGuiApplication>
42 #include <QQmlApplicationEngine>
44 int main(int argc, char *argv[])
46 QGuiApplication app(argc, argv);
47 QQmlApplicationEngine engine;
48 engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
53 \section2 Using C++ Data From QML
55 If you need to register a C++ class to use from QML, you can call
56 qmlRegisterType() before declaring your QQmlApplicationEngine.
57 See \l [QtQml] {Defining QML Types from C++} for more information.
59 If you need to expose data to QML components, you need to make them
60 available to the context of the current QML engine. See QQmlContext for