バインディングの重複

この警告カテゴリーはqmllintによって[duplicate-property-binding]

プロパティでインターセプタが重複している

何が起こりましたか?

一つのプロパティに複数のインターセプタがあります。

なぜ悪いのですか?

同じプロパティに複数のインターセプタを設定することは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 以外を削除してください:

import QtQuick

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

Property Modifier Typesも参照してください

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

何が起こりましたか?

一つのプロパティに複数の値ソースがあります。

これはなぜ悪いのでしょうか?

値ソースが結合されると、予期しない動作を示します。以下の例をご覧ください。

同じプロパティの値ソースとして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 }
}

値のソースとバインディングを結合できません

何が起こったのでしょうか?

1つのプロパティに値ソースとバインディングがあります。

これはなぜ悪いのでしょうか?

バインディングは、値ソースがこのプロパティの更新を開始する前に、プロパティ値を更新します。これは予期しない動作につながる可能性があり、また読みにくくなります。

同じプロパティの値ソースとして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!
}

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