Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
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
10
static
void
withComponent
()
11
{
12
//![QQmlComponent-a]
13
// Using QQmlComponent
14
QQmlEngine engine;
15
QQmlComponent component(&engine,
16
QUrl::fromLocalFile(
"MyItem.qml"
));
17
QObject *object = component.create();
18
//![QQmlComponent-a]
19
}
20
21
int
main
(
int
argc,
char
*argv[])
22
{
23
QGuiApplication app(argc, argv);
24
25
//![QQuickView]
26
// Using QQuickView
27
QQuickView view;
28
view.setSource(QUrl::fromLocalFile(
"MyItem.qml"
));
29
view.show();
30
QObject *object = view.rootObject();
31
//![QQuickView]
32
33
//![properties]
34
object->setProperty(
"width"
, 500);
35
QQmlProperty(object,
"width"
).write(500);
36
//![properties]
37
38
//![cast]
39
QQuickItem *item = qobject_cast<QQuickItem*>(object);
40
item->setWidth(500);
41
//![cast]
42
43
//![findChild]
44
QObject *rect = object->findChild<QObject*>(
"rect"
);
45
if
(rect)
46
rect->setProperty(
"color"
,
"red"
);
47
//![findChild]
48
49
//![QQmlComponent-b]
50
delete
object;
51
//![QQmlComponent-b]
52
53
withComponent
(
)
;
54
55
return
app.exec();
56
}
withComponent
static void withComponent()
[QQuickView-includes]
Definition
main.cpp:10
main
int main(int argc, char *argv[])
[ctor_close]
Definition
src_corelib_animation_qpropertyanimation.cpp:100
qtdeclarative
src
qml
doc
snippets
qml
qtbinding
loading
main.cpp
Generated on
for Qt by
1.18.0