このページでは

コンマ

この警告カテゴリーはqmllintによって[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 は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.