En esta página

Usar función apropiada

Esta categoría de advertencia se escribe [use-proper-function] por qmllint.

La propiedad es una propiedad variante: Puede o no ser un método

¿Qué ha ocurrido?

Has utilizado una propiedad del tipo var como si fuera una función invocable.

¿Por qué es malo?

Esto afecta a la legibilidad del código, el motor QML dará error si la propiedad no contiene una función invocable, y las herramientas QML no pueden aplicar optimizaciones de métodos específicos.

Ejemplo

import QtQuick

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

Para solucionar esta advertencia, declare fun como una función para poder llamarla:

import QtQuick

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

    Component.onCompleted: { fun(); }
}

Property es una propiedad QJSValue: Puede o no ser un método

¿Qué ha ocurrido?

Has utilizado una propiedad del tipo QJSValue como si fuera una función invocable.

Nota: Las propiedades del tipo QJSValue sólo pueden definirse en C++.

¿Por qué es malo?

Es muy probable que la propiedad no estuviera destinada a ser invocada y hará que el motor QML se equivoque en tiempo de ejecución.

Ejemplo

import QtQuick

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

Para solucionar este problema, elimine la llamada a gradient:

import QtQuick

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

Alternativamente, considere reemplazar la definición de la propiedad por un método normal de Q_INVOKABLE o un slot si usted es el autor de la propiedad. Esto sólo es posible si la función no debe modificarse nunca en QML. Si realmente necesitas almacenar una devolución de llamada, no tienes suerte.

La señal está oculta por una propiedad

¿Qué ha ocurrido?

Has llamado a una señal que está oculta por una propiedad o has ocultado una señal con una propiedad.

¿Por qué es malo?

Es muy probable que el autor de la llamada esperara llamar a una señal y no a la propiedad que le hace sombra. Esto puede hacer que el motor QML falle en tiempo de ejecución.

Ejemplo

import QtQuick

Item {
    component Base: Item {
        signal helloSignal
    }

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

Para corregir esta advertencia, cambie el nombre de la propiedad de sombreado:

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

Véase {Signal is shadowed by a property}.

Una propiedad da sombra a una ranura

Ver {Signal is shadowed by a property}.

La propiedad no es un método

¿Qué ha ocurrido?

Ha utilizado una propiedad de un tipo distinto a var o QJSValue como si fuera una función invocable.

¿Por qué es malo?

La propiedad no puede ser llamada y hará que el motor QML falle en tiempo de ejecución.

Ejemplo

import QtQuick

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

Para corregir esta advertencia, elimine la llamada o convierta hello en una función:

import QtQuick

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

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

© 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.