조건문에서 할당 연산자 사용 시 경고 표시
qmllint에서는 이 경고 범주를 ‘ [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
}
}© 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.