Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qtquickcontrols-gettingstarted.qdoc
Go to the documentation of this file.
1
// Copyright (C) 2017 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
3
4
/*!
5
\page qtquickcontrols-gettingstarted.html
6
\keyword Getting Started with Qt Quick Controls 2
7
\title Getting Started with Qt Quick Controls
8
9
A basic example of a QML file that makes use of controls is shown here:
10
11
\qml
12
import QtQuick
13
import QtQuick.Controls
14
15
ApplicationWindow {
16
title: "My Application"
17
width: 640
18
height: 480
19
visible: true
20
21
Button {
22
text: "Push Me"
23
anchors.centerIn: parent
24
}
25
}
26
\endqml
27
28
\section1 Setting Up Controls from C++
29
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
32
C++.
33
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.
37
38
A basic example of a source file that makes use of controls is shown here:
39
40
\code
41
#include <QGuiApplication>
42
#include <QQmlApplicationEngine>
43
44
int main(int argc, char *argv[])
45
{
46
QGuiApplication app(argc, argv);
47
QQmlApplicationEngine engine;
48
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
49
return app.exec();
50
}
51
\endcode
52
53
\section2 Using C++ Data From QML
54
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.
58
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
61
more information.
62
*/
qtdeclarative
src
quickcontrols
doc
src
qtquickcontrols-gettingstarted.qdoc
Generated on
for Qt by
1.14.0