리터럴 생성자
qmllint에서는 이 경고 범주를 ‘ [literal-constructors] ’라고 표기합니다.
함수를 생성자로 사용하지 마십시오
무슨 일이 발생했나요?
리터럴 생성자 함수가 생성자로 사용되었습니다.
왜 문제가 될까요?
Number 와 같은 리터럴 생성 함수를 일반 함수처럼 호출하면, 전달된 값이 기본형 숫자로 강제 변환됩니다. 반면, Number 를 생성자로 호출하면 해당 값을 포함하는 Number 에서 파생된 객체가 반환됩니다. 이는 자원 낭비이며, 의도한 결과가 아닐 가능성이 높습니다. 게다가 반환된 값이 기본형이 아니기 때문에 예상치 못한 동작이나 혼란을 초래할 수 있습니다.
예시
import QtQuick
Item {
function numberify(x) {
return new Number(x)
}
Component.onCompleted: {
let n = numberify("1")
console.log(typeof n) // object
console.log(n === 1) // false
if (new Boolean(false)) // All objects are truthy!
console.log("aaa") // aa
}
}이 경고를 해결하려면, 해당 함수들을 생성자가 아닌 일반 함수로 호출하십시오:
import QtQuick
Item {
function numberify(x) {
return Number(x)
}
Component.onCompleted: {
let n = numberify("1")
console.log(typeof n) // number
console.log(n === 1) // true
if (Boolean(false))
console.log("aaa") // <not executed>
}
}Array의 의미 체계가 혼란스럽습니다
무슨 일이 있었나요?
Array 생성자가 두 개 이상의 인자와 함께 사용되었습니다.
왜 문제가 될까요?
Array 생성자는 의미론이 모호합니다:
new Array()빈 배열을 생성합니다.new Array(42)42개의 요소를 가진 배열을 생성합니다.new Array(42, 43)42와 43이라는 두 개의 요소를 가진 배열을 생성합니다.
예시
import QtQuick
Item {
function createArray() {
return new Array(1, 2, 3)
}
}이 경고를 해결하려면 ` new Array(...)` 대신 ` [...] `을 사용하십시오.
함수:
import QtQuick
Item {
function createArray() {
return [1, 2, 3]
}
}© 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.