このページでは

重複するバインディング

この警告カテゴリは、qmllint によって「[duplicate-property-binding] 」と表記されます。

プロパティ上のインターセプタの重複

何が起きたのか?

1つのプロパティに複数のインターセプタが設定されています。

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

同じプロパティに複数のインターセプタを設定することは、QML エンジンではサポートされていません。

例

同じプロパティに対して「Behavior 」を2回インターセプターとして使用してみましょう:

import QtQuick

Rectangle {
    Behavior on width {
        NumberAnimation { duration: 1000 }
    }
    Behavior on width { // not ok: Duplicate interceptor on property "width" [duplicate-property-binding]
        NumberAnimation { duration: 2000 }
    }
}

この警告を解消するには、Behavior を1つだけ残して、残りをすべて削除してください:

import QtQuick

Rectangle {
    Behavior on width {
        NumberAnimation { duration: 2000 }
    }
}

「プロパティ修飾子の種類」も参照してください。

プロパティの値ソースが重複しています

何が起きたのか?

1つのプロパティに複数の値ソースが設定されています。

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

これらの値ソースを組み合わせると、予期しない動作が発生します。以下の例を参照してください。

例

同じプロパティに対して、NumberAnimation を値ソースとして2回使用してみましょう:

import QtQuick

Rectangle {
    NumberAnimation on x { to: 50; duration: 1000 }
    NumberAnimation on x { to: 10; duration: 100 } // not ok: Duplicate value source on property "x" [duplicate-property-binding]

    onXChanged: console.log(x)
}

そのプログラムの出力を確認すると、2つの`NumberAnimation `が互いに交錯していることがわかりますが、これはおそらく意図した効果ではないでしょう。この警告を解消するには、`NumberAnimation`を1つだけ残して、残りをすべて削除します:

import QtQuick

Rectangle {
    NumberAnimation on x { to: 50; duration: 1000 }
}

値ソースとバインディングを組み合わせることができません

何が起きたのでしょうか?

あるプロパティに対して、同じプロパティに値ソースとバインディングが両方設定されています。

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

バインディングによってプロパティの値が更新されてしまい、その後に値ソースがこのプロパティの更新を開始することになります。これにより予期しない動作を引き起こす可能性があり、またコードの可読性も低下します。

例

同じプロパティに対して、NumberAnimation を値ソースとして使用してみましょう:

import QtQuick

Rectangle {
    NumberAnimation on x { to: 50; duration: 1000 } // not ok: Cannot combine value source and binding on property "x" [duplicate-property-binding]
    x: 55

    onXChanged: console.log(x)
}

このプログラムの出力を確認すると、NumberAnimation が55から50へとアニメーションすることがわかります。以下のコードの方が読みやすくなります:

import QtQuick

Rectangle {
    NumberAnimation on x { from: 55; to: 50; duration: 1000 } // ok: intentions are clearer now!
}

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