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
main.cpp
Go to the documentation of this file.
1// Copyright (C) 2017 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3#include <QGuiApplication>
4#include <QtQml>
5//![QQuickView-includes]
6#include <QQuickView>
7#include <QQuickItem> // to convert rootObject() to QObject *
8//![QQuickView-includes]
9
10static void withComponent()
11{
12//![QQmlComponent-a]
13// Using QQmlComponent
14QQmlEngine engine;
15QQmlComponent component(&engine,
16 QUrl::fromLocalFile("MyItem.qml"));
17QObject *object = component.create();
18//![QQmlComponent-a]
19}
20
21int main(int argc, char *argv[])
22{
23 QGuiApplication app(argc, argv);
24
25//![QQuickView]
26// Using QQuickView
27QQuickView view;
28view.setSource(QUrl::fromLocalFile("MyItem.qml"));
29view.show();
30QObject *object = view.rootObject();
31//![QQuickView]
32
33//![properties]
34object->setProperty("width", 500);
35QQmlProperty(object, "width").write(500);
36//![properties]
37
38//![cast]
39QQuickItem *item = qobject_cast<QQuickItem*>(object);
40item->setWidth(500);
41//![cast]
42
43//![findChild]
44QObject *rect = object->findChild<QObject*>("rect");
45if (rect)
46 rect->setProperty("color", "red");
47//![findChild]
48
49//![QQmlComponent-b]
50delete object;
51//![QQmlComponent-b]
52
54
55 return app.exec();
56}
static void withComponent()
[QQuickView-includes]
Definition main.cpp:10
int main(int argc, char *argv[])
[ctor_close]