このページでは

Qt Quick コントロールの入門

コントロールを使用した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 」を参照してください。

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