Auf dieser Seite

Bewertung

Diese Warnkategorie wird von qmllint mit [eval] geschrieben.

Verwenden Sie nicht eval

Was ist passiert?

Sie haben eval in Ihrem Code verwendet.

Warum ist das schlecht?

Die Methode eval ist langsam und potenziell gefährlich. eval führt sein Argument aus, als wäre es ein eigenes JavaScript-Skript, was einen gewissen Overhead bei der Ausführung verursacht. Das Argument, das an eval übergeben wird, ist ein potenzieller Vektor für Angriffe auf entfernte Codeausführung.

Beispiel

import QtQuick

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

Um diese Warnung zu beheben, schreiben Sie den Code so um, dass er keine eval -Aufrufe enthält.

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.