Sur cette page

Fonction utilisée avant sa déclaration

Cette catégorie d'avertissement est orthographiée « [function-used-before-declaration] » par qmllint.

Cette catégorie est désactivée par défaut.

Utilisation d'une fonction avant sa déclaration

Que s'est-il passé ?

Vous avez appelé une fonction ou utilisé son nom avant que celle-ci ne soit déclarée.

Pourquoi est-ce un problème ?

Cela rend le code plus difficile à lire et peut prêter à confusion.

Notez que la fonction est disponible avant sa déclaration en raison du hoisting.

Exemple

import QtQuick

Item {
    function f() {
        g(42)
        function g() { return 42; }
    }
}

Pour corriger cet avertissement, placez la déclaration avant l'utilisation.

import QtQuick

Item {
    function f() {
        function g() { return 42; }
        g(42)
    }
}

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