QtObject QML Type
Um tipo básico do QML. Mais...
Propriedades
- objectName : string
Descrição detalhada
O tipo QtObject é um elemento não visual que contém apenas a propriedade ` objectName `.
Pode ser útil criar um QtObject se você precisar de um tipo extremamente leve para abrigar um conjunto de propriedades personalizadas:
import QtQuick
Item {
QtObject {
id: attributes
property string name
property int size
property variant attributes
}
Text { text: attributes.name }
}Também pode ser útil para integração com C++, já que se trata apenas de um ` QObject` simples. Consulte a documentação de ` QObject ` para obter mais detalhes.
Documentação de propriedades
objectName : string
Essa propriedade contém o QObject::objectName dessa instância específica do objeto.
Isso permite que um aplicativo em C++ localize um item dentro de um componente QML usando o método ` QObject::findChild()`. Por exemplo, o aplicativo em C++ a seguir localiza o item filho ` Rectangle ` e altera dinamicamente seu 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.