블록 범위 변수 선언
qmllint에서는 이 경고 범주를 ' [block-scope-var-declaration] '로 표기합니다.
블록 범위 내에서 var를 사용하여 변수가 선언되었습니다.
무슨 일이 발생했나요?
JavaScript 변수가 블록 범위 내부(예: while 루프의 본문)에서 var를 사용하여 선언되었습니다. 변수가 해당 범위 내에서만 사용 가능한 것처럼 보일 수 있지만, 실제로는 가장 안쪽의 함수 또는 QML 바인딩의 범위로 호이스팅(hoisted)되므로 범위 외부에서도 접근할 수 있습니다.
왜 문제가 될까요?
이러한 변수의 범위를 파악하기 어려울 수 있으며, 의도치 않게 다른 변수를 가릴 수도 있습니다.
예시
import QtQuick
Item {
id: root
property int count: 0
function countItems() {
let sum = 0
{
var count = root.children.length
sum += count
}
// ... more additions to sum
count = sum // modifies the function local variable, not root.count
}
}이 경고를 해결하려면 대신 `let`이나 `const`를 사용하거나, 함수 범위 내에서 직접 변수를 선언하십시오.
© 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.