쉼표
이 경고 범주는 qmllint에서 ' [comma] '로 표기됩니다.
쉼표 표현식을 사용하지 마십시오
무슨 일이 있었나요?
for 루프 외부에서 JavaScript 쉼표 표현식이 사용되었습니다.
왜 문제가 될까요?
쉼표 표현식은 코드의 가독성을 떨어뜨리고 부수 효과를 모호하게 만듭니다.
예시
import QtQuick
Item {
Component.onCompleted: init(config, true), enableLogging(categories), run(1000) // millis
}이 경고를 해결하려면, 각 연산에 대해 별도의 문을 사용하도록 코드를 리팩토링하십시오. 이렇게 하면 각 부수 효과가 다른 관련 없는 연산의 일부로 발생하는 대신 명시적으로 드러납니다:
import QtQuick
Item {
Component.onCompleted: {
init(config, true)
enableLogging(categories)
run(1000) // millis
}
}또한, 다음 코드에서와 같이 바인딩을 위해 변수를 의도적으로 캡처함으로써 쉼표 표현식이 나타나는 경우에 대한 몇 가지 특별한 고려 사항이 있습니다. 여기서 ` previewOfFirstPage `는 C++로 정의된 함수이며, 내부적으로 ` Config.fontSize`에 의존합니다:
Text {
// This causes the function to re-run when fontSize changes
text: Config.fontSize, documentProvider.previewOfFirstPage()
}이러한 상황이 발생하면 다음 접근 방식 중 하나를 고려해 보십시오:
previewOfFirstPage과 같은 함수가 속성에 의존하는 경우, 해당 값을 인수로 전달하여 이 의존성을 명시적으로 만드는 것을 선호하십시오.Text { text: documentProvider.previewOfFirstPage(Config.fontSize) }- API상의 이유로 함수 시그니처를 변경하는 것이 바람직하지 않다면, 해당 함수를 Q_PROPERTY 로 대체하는 것을 고려해 보십시오. 이렇게 하면 C++에서 의존성이 수정될 때 이에 대한 변경 알림이 발송될 수 있습니다:
void Config::setFontSize(int fontSize) { if (m_fontSize == fontSize) return; m_fontSize = fontSize; emit fontSizeChanged(); emit previewOfFirstPageChanged(); }Text { text: documentProvider.previewOfFirstPage } - C++ 구현을 수정하거나 QML 종속성을 추가할 수 없는 경우, `
qmllint` 지시어를 사용하여 경고를 무시하십시오. 바인딩에서 해당 변수를 캡처하려는 의도임을 설명하는 주석을 포함하십시오.Text { // This causes the function to re-run when fontSize changes text: Config.fontSize, documentProvider.previewOfFirstPage() // qmllint disable comma }
© 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.