QtObject QML Type▲
-
Import Statement: import QtQml
-
Inherited By:: Action, ActionGroup, ButtonGroup, ColorGroup, Dialog, Direction3D, EmitBurst3D, GraphicsApiFilter, Item, ItemGrabResult, KeyboardStyle, Keyframe, KeyframeGroup, Menu, MenuBar, MenuItem, MenuItemGroup, MorphTarget, Object3D, ParticleAbstractShape3D, ParticleSystem3DLogging, PdfStyle, Popup, SplitHandle, SpriteSequence3D, StandardPaths, StencilOperationArguments, StencilTestArguments, SystemInformation, SystemTrayIcon, and Timeline
-
Instantiates:: QObject
-
Group: QtObject is part of qml-utility-elements
Detailed Description▲
The QtObject type is a non-visual element which contains only the objectName property.
It can be useful to create a QtObject if you need an extremely lightweight type to enclose a set of custom properties:
import
QtQuick 2.0
Item
{
QtObject
{
id
:
attributes
property
string
name
property
int
size
property
variant attributes
}
Text
{
text
:
attributes.name }
}
It can also be useful for C++ integration, as it is just a plain QObject. See the QObject documentation for further details.
Property Documentation▲
objectName : string▲
This property holds the QObject::objectName for this specific object instance.
This allows a C++ application to locate an item within a QML component using the QObject::findChild() method. For example, the following C++ application locates the child Rectangle item and dynamically changes its color value:
// MyRect.qml
import
QtQuick 2.0
Item
{
width
:
200
; height
:
200
Rectangle
{
anchors.fill
:
parent
color
:
"red"
objectName
:
"myRect"
}
}
// main.cpp
QQuickView view;
view.setSource(QUrl::
fromLocalFile("MyRect.qml"
));
view.show();
QQuickItem *
item =
view.rootObject()-&
gt;findChild&
lt;QQuickItem*&
gt;("myRect"
);
if
(item)
item-&
gt;setProperty("color"
, QColor(Qt::
yellow));