En esta página

QtObject QML Type (Singleton)

Un tipo QML básico. Más...

Import Statement: import QtQml
In C++: QObject
Inherited By:
128 types

AbstractButton, Action, ActionGroup, AnimatedImage, AnimatedSprite, BorderImage, BusyIndicator, Button, ButtonGroup, Calendar, Canvas, CheckBox, CheckDelegate, ColorGroup, ColorOpacityAnimation, Column, ColumnLayout, ComboBox, Container, Control, DayOfWeekRow, DelayButton, Dial, Dialog, DialogButtonBox, DoubleSpinBox, Drawer, DropArea, EllipseShape, Filter, FlexboxLayout, Flickable, Flipable, Flow, FocusScope, Frame, FunctionFilter, FunctionSorter, Grid, GridLayout, GridView, GroupBox, HorizontalHeaderView, HorizontalHeaderViewDelegate, Image, ImageParticle, Item, ItemDelegate, ItemGrabResult, ItemParticle, Label, LayoutItemProxy, ListView, Loader, MaskShape, Menu, MenuBar, MenuBarItem, MenuItem, MenuSeparator, MonthGrid, MouseArea, MultiEffect, MultiPointTouchArea, Overlay, Page, PageIndicator, Palette, Pane, ParticlePainter, PathView, PinchArea, Popup, ProgressBar, RadioButton, RadioDelegate, RangeSlider, Rectangle, RectangularShadow, Repeater, RoleFilter, RoleSorter, RoundButton, Row, RowLayout, ScrollBar, ScrollIndicator, ScrollView, SearchField, SelectionRectangle, ShaderEffect, ShaderEffectSource, Shape, Slider, Sorter, SpinBox, SplitHandle, SplitView, SpriteSequence, StackLayout, StackView, StringSorter, SwipeDelegate, SwipeView, Switch, SwitchDelegate, TabBar, TabButton, TableView, TableViewDelegate, Text, TextArea, TextEdit, TextField, TextInput, ToolBar, ToolButton, ToolSeparator, ToolTip, TreeView, TreeViewDelegate, Tumbler, ValueFilter, VectorImage, VerticalHeaderView, VerticalHeaderViewDelegate, WeekNumberColumn, and WindowContainer

Nota: Este tipo es un singleton QML. Sólo hay una instancia de este tipo en el motor QML.

Propiedades

Descripción detallada

El tipo QtObject es un elemento no visual que contiene únicamente la propiedad objectName.

Puede ser útil crear un QtObject si necesitas un tipo extremadamente ligero para encerrar un conjunto de propiedades personalizadas:

import QtQuick

Item {
    QtObject {
        id: attributes
        property string name
        property int size
        property variant attributes
    }

    Text { text: attributes.name }
}

También puede ser útil para la integración de C++, ya que es simplemente un QObject. Consulte la documentación de QObject para más detalles.

Documentación de propiedades

objectName : string

Esta propiedad contiene el QObject::objectName para esta instancia de objeto específica.

Esto permite a una aplicación C++ localizar un elemento dentro de un componente QML utilizando el método QObject::findChild(). Por ejemplo, la siguiente aplicación C++ localiza el elemento hijo Rectangle y cambia dinámicamente su valor color:

// 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()->findChild<QQuickItem*>("myRect");
if (item)
    item->setProperty("color", QColor(Qt::yellow));

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.