適切な機能を使用する
この警告カテゴリーはqmllintによって[use-proper-function]
。
Propertyはバリアントプロパティです:メソッドであるかどうか
何が起こったのですか?
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(); } } }
メソッドはプロパティによってシャドウイングされる
参照:{Signal is shadowed by a property}.
スロットがプロパティによってシャドウイングされている
シグナルがプロパティによってシャドウイングされている}を参照してください。
プロパティはメソッドではない
何が起こったのでしょうか?
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.