コンマ
この警告カテゴリは、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.