Sur cette page

Eval

Cette catégorie d'avertissement est orthographiée [eval] par qmllint.

Ne pas utiliser eval

Qu'est-ce qui s'est passé ?

Vous avez utilisé eval dans votre code.

Pourquoi est-ce mauvais ?

La méthode eval est lente et potentiellement dangereuse. eval exécute son argument comme s'il s'agissait de son propre script JavaScript, ce qui ajoute une certaine surcharge à l'exécution. L'argument transmis à eval est potentiellement un vecteur d'exécution de code à distance.

Exemple

import QtQuick

Item {
    function f() {
        let myString = "x",
        myObject = {
            x: 10
        },
        value = eval("myObject." + myString);
    }
}

Pour corriger cet avertissement, réécrivez le code de manière à ce qu'il ne contienne aucun appel à eval.

import QtQuick

Item {
    function f() {
        let myString = "x",
        myObject = {
            x: 10
        },
        value = myObject[myString];
    }
}

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