- Qt 6.10
- Qt Qml
- QML Lint Warning and Errors
- Use proper function
- Qt 6.10.1 Reference Documentation

# Use proper function

This warning category is spelled `[use-proper-function]` by qmllint.

## Property is a variant property: It may or may not be a method

### What happened?

You used a property of the type var as if it were a callable function.

### Why is this bad?

This affects the readability of the code, the QML engine will error out if the property does not contain a callable function, and the QML tooling can't apply specific method optimizations.

### Example

     import QtQuick

     Item {
         property var fun: () => console.log("Hello")
         Component.onCompleted: { fun(); }
     }

To fix this warning, declare `fun` as a function to be able to call it:

     import QtQuick

     Item {
         function fun() {
             console.log("Hello")
         }

         Component.onCompleted: { fun(); }
     }

## Property is a QJSValue property: It may or may not be a method

### What happened?

You used a property of the type `QJSValue` as if it were a callable function.

Note: Properties of the type QJSValue can only be defined in C++.

### Why is this bad?

The property was very probably not meant to be called and will make the QML engine error out at runtime.

### Example

     import QtQuick

     Rectangle {
         // Rectangle has a property gradient of the type QJSValue
         Component.onCompleted: { console.log(gradient()); }
     }

To fix this warning, remove the call to `gradient`:

     import QtQuick

     Item {
         // Rectangle has a property gradient of the type QJSValue
         Component.onCompleted: { console.log(gradient); }
     }

Alternatively, consider replacing the property definition with a regular Q_INVOKABLE method or a slot if you are the author of the property. This is only possible if the function is never meant to be changed in QML. If you actually need to store a callback, you're out of luck.

## Signal is shadowed by a property

### What happened?

You called a signal that is shadowed by a property or you shadowed a signal with a property.

### Why is this bad?

The caller very probably expected to call a signal, and not the shadowing property. This could make the QML engine error out at runtime.

### Example

     import QtQuick

     Item {
         component Base: Item {
             signal helloSignal
         }

         Base {
             property int helloSignal // shadows helloSignal inherited from Base
             Component.onCompleted: { helloSignal(); }
         }
     }

To fix this warning, rename the shadowing property:

     import QtQuick

     Item {
         component Base: Item {
             signal helloSignal
         }

         Base {
             property int helloSignal2 // does not shadow anymore
             Component.onCompleted: { helloSignal(); }
         }
     }

## Method is shadowed by a property

See {Signal is shadowed by a property}.

## Slot is shadowed by a property

See {Signal is shadowed by a property}.

## Property is not a method

### What happened?

You used a property of a type other than var or `QJSValue` as if it were a callable function.

### Why is this bad?

The property can't be called and will make the QML engine error out at runtime.

### Example

     import QtQuick

     Item {
         property int hello
         Component.onCompleted: { console.log(hello()); }
     }

To fix this warning, remove the call or make `hello` a function:

     import QtQuick

     Item {
         property int hello
         Component.onCompleted: { console.log(hello); }

         // alternative:
         function helloAlternative() { ... }
         Component.onCompleted: { console.log(helloAlternative()); }
     }