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#include <QtQuick>
6
7static void withComponent()
8{
9//![QQmlComponent-a]
10// Using QQmlComponent
11QQmlEngine engine;
12QQmlComponent component(&engine,
13 QUrl::fromLocalFile("MyItem.qml"));
14QObject *object = component.create();
15//![QQmlComponent-a]
16}
17
18int main(int argc, char *argv[])
19{
20 QGuiApplication app(argc, argv);
21
22//![QQuickView]
23// Using QQuickView
24QQuickView view;
25view.setSource(QUrl::fromLocalFile("MyItem.qml"));
26view.show();
27QObject *object = view.rootObject();
28//![QQuickView]
29
30//![properties]
31object->setProperty("width", 500);
32QQmlProperty(object, "width").write(500);
33//![properties]
34
35//![cast]
36QQuickItem *item = qobject_cast<QQuickItem*>(object);
37item->setWidth(500);
38//![cast]
39
40//![findChild]
41QObject *rect = object->findChild<QObject*>("rect");
42if (rect)
43 rect->setProperty("color", "red");
44//![findChild]
45
46//![QQmlComponent-b]
47delete object;
48//![QQmlComponent-b]
49
51
52 return app.exec();
53}
static void withComponent()
Definition main.cpp:7
int main(int argc, char *argv[])
[ctor_close]