このページでは

紛らわしいマイナス記号

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

紛らわしいマイナス記号

何が問題なのか?

JavaScript コードで、「-」で記述された演算子が紛らわしい形で組み合わされています。隣接する「-」演算子を区別するのが難しい場合があります。また、慣例に反するスペースの入れ方によって、この問題がさらに悪化する可能性があります。

なぜ問題なのか?

コードの可読性が低下し、混乱を招く恐れがあります。

例

import QtQuick

Item {
    function f(a: int, b: int) {
        let x = a-- - b
        let y = a - -b
        let z = a - --b
        return x + y + z
    }
}

この警告を解消するには、類似した「-」演算子が隣り合わないようにコードを書き直してください。可能な場合は式を簡略化してください。不要な単項演算子やスペースを削除し、括弧を使って部分式を区切ってください。

これらの演算子が型変換を行う可能性があることに注意してください。a - -b のような式は、b の型によってはa + b と同等ではない場合があります。

import QtQuick

Item {
    function f(a: int, b: int) {
        let x = (a--) - b
        let y = a + b
        let z = a - b + 1
        return x + y + z
    }
}

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