Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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{
10// Using QQmlComponent
13 QUrl::fromLocalFile("MyItem.qml"));
14QObject *object = component.create();
16}
17
18int main(int argc, char *argv[])
19{
20 QGuiApplication app(argc, argv);
21
23// Using QQuickView
26view.show();
27QObject *object = view.rootObject();
29
31object->setProperty("width", 500);
32QQmlProperty(object, "width").write(500);
34
37item->setWidth(500);
39
41QObject *rect = object->findChild<QObject*>("rect");
42if (rect)
43 rect->setProperty("color", "red");
45
47delete object;
49
51
52 return app.exec();
53}
54
static int exec()
Enters the main event loop and waits until exit() is called, then returns the value that was set to e...
\macro qGuiApp
\inmodule QtCore
Definition qobject.h:103
T findChild(QAnyStringView aName, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
Returns the child of this object that can be cast into type T and that is called name,...
Definition qobject.h:155
bool setProperty(const char *name, const QVariant &value)
Sets the value of the object's name property to value.
The QQmlComponent class encapsulates a QML component definition.
The QQmlEngine class provides an environment for instantiating QML components.
Definition qqmlengine.h:57
The QQmlProperty class abstracts accessing properties on objects created from QML.
bool write(const QVariant &) const
Sets the property value to value.
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
Definition qquickitem.h:63
The QQuickView class provides a window for displaying a Qt Quick user interface.
Definition qquickview.h:20
void setSource(const QUrl &)
Sets the source to the url, loads the QML component and instantiates it.
QQuickItem * rootObject() const
Returns the view's root \l {QQuickItem} {item}.
static QUrl fromLocalFile(const QString &localfile)
Returns a QUrl representation of localFile, interpreted as a local file.
Definition qurl.cpp:3368
void show()
Shows the window.
Definition qwindow.cpp:2254
int main()
[0]
rect
[4]
GLuint object
[3]
static qreal component(const QPointF &point, unsigned int i)
QQuickItem * qobject_cast< QQuickItem * >(QObject *o)
Definition qquickitem.h:492
static void withComponent()
Definition main.cpp:7
QGraphicsItem * item
QApplication app(argc, argv)
[0]
QQuickView * view
[0]
QJSEngine engine
[0]