条件内での代入の使用に関する警告
この警告カテゴリーはqmllintによって[warn-assignment-in-condition]
。
条件内での代入の使用に関する警告
何が起こりましたか?
if-condition
の中で代入を使いました。
これはなぜ悪いのですか?
これはしばしば間違いで、比較を使うべきでした。もし意図的であったとしても、しばしば混乱を招くと考えられます。
例
import QtQuick Item { id: root Component.onCompleted: { // mistake: should have been a comparison if (width = height) console.log("A square") let mypoint = Qt.point(1,2) let hit = false // intentional, but possibly misleading if (hit = root.contains(myPoint)) console.log("hit") root.enabled = hit } }
この警告を修正するには、もし間違いであれば、代入を比較に変更してください。そうでない場合は、代入を括弧で囲み、意図的に行われたことを示します。
import QtQuick Item { id: root Component.onCompleted: { // fixed if (width === height) console.log("A square") let mypoint = Qt.point(1,2) let hit = false // intentional if ((hit = root.contains(point))) console.log("hit") root.enabled = hit } }
© 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.