시작하기 Qt Quick Controls

컨트롤을 사용하는 QML 파일의 기본 예제는 다음과 같습니다:

import QtQuick
import QtQuick.Controls

ApplicationWindow {
    title: "My Application"
    width: 640
    height: 480
    visible: true

    Button {
        text: "Push Me"
        anchors.centerIn: parent
    }
}

C++에서 컨트롤 설정하기

QQuickView 은 전통적으로 C++ 애플리케이션에서 QML 파일을 표시하는 데 사용되었지만, 이렇게 하면 C++ 에서만 창 속성을 설정할 수 있습니다.

Qt Quick Controls 을 사용하여 ApplicationWindow 을 애플리케이션의 루트 항목으로 선언하고 대신 QQmlApplicationEngine 을 사용하여 실행하세요. 이렇게 하면 QML에서 최상위 창 속성을 제어할 수 있습니다.

컨트롤을 사용하는 소스 파일의 기본 예는 여기에 나와 있습니다:

#include <QGuiApplication>
#include <QQmlApplicationEngine>

int main(int argc, char *argv[])
{
    QGuiApplication app(argc, argv);
    QQmlApplicationEngine engine;
    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
    return app.exec();
}

QML에서 C++ 데이터 사용

QML에서 사용할 C++ 클래스를 등록해야 하는 경우 QQmlApplicationEngine 을 선언하기 전에 qmlRegisterType()을 호출하면 됩니다. 자세한 내용은 C++에서 QML 유형 정의하기를 참조하세요.

QML 컴포넌트에 데이터를 노출해야 하는 경우 현재 QML 엔진의 컨텍스트에서 데이터를 사용할 수 있도록 설정해야 합니다. 자세한 내용은 QQmlContext 을 참조하세요.

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