이 페이지에서

콤마

이 경고 카테고리의 철자는 [comma] 입니다.

쉼표 표현식을 사용하지 마세요.

무슨 일이 있었나요?

JavaScript 쉼표 표현식이 for 루프 외부에서 사용되었습니다.

이것이 왜 나쁜가요?

쉼표 표현식은 코드의 가독성을 떨어뜨리고 부작용을 유발합니다.

예시

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 는 내부적으로 Config.fontSize 에 종속되는 C++ 로 정의된 함수인 경우와 같이 변수가 의도적으로 바인딩을 위해 캡처되어 쉼표 표현식이 나타나는 경우 몇 가지 특별한 고려 사항이 있습니다:

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.