QtObject QML Type
Un tipo QML di base. Maggiori informazioni...
Proprietà
- objectName : string
Descrizione dettagliata
Il tipo QtObject è un elemento non visivo che contiene solo la proprietà objectName.
Può essere utile creare un QtObject se si ha bisogno di un tipo estremamente leggero per racchiudere un insieme di proprietà personalizzate:
import QtQuick
Item {
QtObject {
id: attributes
property string name
property int size
property variant attributes
}
Text { text: attributes.name }
}Può essere utile anche per l’integrazione con C++, poiché si tratta semplicemente di un semplice oggetto ` QObject`. Per ulteriori dettagli, consultare la documentazione su ` QObject `.
Documentazione sulle proprietà
objectName : string
Questa proprietà contiene l'QObject::objectName per questa specifica istanza dell'oggetto.
Ciò consente a un'applicazione C++ di individuare un elemento all'interno di un componente QML utilizzando il metodo ` QObject::findChild()`. Ad esempio, la seguente applicazione C++ individua l'elemento figlio ` Rectangle ` e modifica dinamicamente il suo valore ` 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.