このページについて

var ではないプロパティを優先する

この警告カテゴリは、qmllint では「[prefer-non-var-properties] 」と表記されます。

var よりもより具体的な型を優先する

何が起きたのか?

QML でプロパティを定義する際、int やstring といったより具体的な型ではなく、var という型を使用しました。

なぜこれが問題なのでしょうか?

コードの可読性に影響するほか、QML ツールが特定の型に対する最適化を適用できなくなります。

常に同じ型を保持するプロパティについては、var をプロパティ型として使用することを避けるべきです。誤検知を防ぐため、qmllint は単純なバインディングを持つ読み取り専用プロパティについてのみ警告を出します。それ以外の場合、複数の型を保持する必要があるため `var` 型でなければならないプロパティと、常に同じ型を保持するプロパティとを区別できない可能性があります。

例

import QtQuick

Item {
    readonly property var myP: 42
}

この警告を修正するには、var を具体的な型に置き換えてください。

import QtQuick

Item {
    readonly property int myP: 42
}

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