QtObject QML Type

기본 QML 유형입니다. 더 보기...

Import Statement: import QtQml
In C++: QObject

속성

상세 설명

QtObject 유형은 objectName 속성만 포함하는 비시각적 요소입니다.

사용자 정의 프로퍼티 세트를 둘러싸기 위해 매우 가벼운 타입이 필요한 경우 QtObject를 만드는 것이 유용할 수 있습니다:

import QtQuick

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

    Text { text: attributes.name }
}

그냥 평범한 QObject 이므로 C++ 통합에도 유용할 수 있습니다. 자세한 내용은 QObject 문서를 참조하세요.

프로퍼티 문서

objectName : string

이 프로퍼티는 이 특정 객체 인스턴스에 대한 QObject::objectName 을 보유합니다.

이를 통해 C++ 애플리케이션은 QObject::findChild() 메서드를 사용하여 QML 컴포넌트 내에서 항목을 찾을 수 있습니다. 예를 들어, 다음 C++ 애플리케이션은 하위 Rectangle 항목을 찾아 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));

© 2025 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.