적절한 기능 사용
이 경고 카테고리의 철자는 [use-proper-function]
입니다.
속성은 변형 속성입니다: 메서드일 수도 있고 아닐 수도 있습니다.
무슨 일이 있었나요?
var 유형의 프로퍼티를 호출 가능한 함수인 것처럼 사용했습니다.
이것이 왜 나쁜가요?
이는 코드의 가독성에 영향을 미치고, 프로퍼티에 호출 가능한 함수가 포함되어 있지 않으면 QML 엔진에서 오류가 발생하며, QML 툴링이 특정 메서드 최적화를 적용할 수 없습니다.
예제
import QtQuick Item { property var fun: () => console.log("Hello") Component.onCompleted: { fun(); } }
이 경고를 해결하려면 fun
을 호출할 수 있는 함수로 선언하세요:
import QtQuick Item { function fun() { console.log("Hello") } Component.onCompleted: { fun(); } }
Property는 QJSValue 속성입니다: 메서드일 수도 있고 아닐 수도 있습니다.
무슨 일이 있었나요?
QJSValue
유형의 프로퍼티를 호출 가능한 함수인 것처럼 사용했습니다.
참고: QJSValue 유형의 프로퍼티는 C++에서만 정의할 수 있습니다.
이것이 왜 나쁜가요?
이 프로퍼티는 호출할 수 있는 함수가 아니므로 런타임에 QML 엔진이 오류를 발생시킬 가능성이 높습니다.
예제
import QtQuick Rectangle { // Rectangle has a property gradient of the type QJSValue Component.onCompleted: { console.log(gradient()); } }
이 경고를 수정하려면 gradient
에 대한 호출을 제거하세요:
import QtQuick Item { // Rectangle has a property gradient of the type QJSValue Component.onCompleted: { console.log(gradient); } }
또는 프로퍼티의 작성자인 경우 프로퍼티 정의를 일반 Q_INVOKABLE 메서드나 슬롯으로 대체하는 것을 고려해 보세요. 이는 함수가 QML에서 변경되지 않아야 하는 경우에만 가능합니다. 실제로 콜백을 저장해야 하는 경우라면 운이 나쁩니다.
신호가 프로퍼티에 의해 그림자 처리됨
어떻게 된 걸까요?
프로퍼티에 의해 섀도잉된 시그널을 호출했거나 프로퍼티가 있는 시그널을 섀도잉했습니다.
이것이 왜 나쁜가요?
호출자가 섀도잉 프로퍼티가 아닌 시그널을 호출할 것으로 예상했을 가능성이 높습니다. 이로 인해 런타임에 QML 엔진이 오류를 일으킬 수 있습니다.
예제
import QtQuick Item { component Base: Item { signal helloSignal } Base { property int helloSignal // shadows helloSignal inherited from Base Component.onCompleted: { helloSignal(); } } }
이 경고를 해결하려면 섀도잉 프로퍼티의 이름을 바꾸세요:
import QtQuick Item { component Base: Item { signal helloSignal } Base { property int helloSignal2 // does not shadow anymore Component.onCompleted: { helloSignal(); } } }
메서드가 속성에 의해 섀도잉됨
시그널이 속성에 의해 섀도잉됨}을 참조하세요.
슬롯이 속성에 의해 섀도잉됨
신호가 속성에 의해 섀도잉되었습니다}를 참조하세요.
프로퍼티가 메서드가 아닙니다.
무슨 일이 있었나요?
var 또는 QJSValue
이외의 유형의 프로퍼티를 호출 가능한 함수인 것처럼 사용했습니다.
이것이 왜 나쁜가요?
해당 프로퍼티는 호출할 수 없으며 런타임에 QML 엔진에서 오류가 발생합니다.
예제
이 경고를 해결하려면 호출을 제거하거나 hello
을 함수로 만드세요:
import QtQuick Item { property int hello Component.onCompleted: { console.log(hello); } // alternative: function helloAlternative() { ... } Component.onCompleted: { console.log(helloAlternative()); } }
© 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.