In questa pagina

Stringhe su più righe

Questa categoria di avviso viene indicata da qmllint come " [multiline-strings] ".

La stringa contiene un terminatore di riga non sfuggito, che è deprecato

Cosa è successo?

Una stringa si estende su più righe.

Perché è un problema?

Le stringhe che si estendono su più righe sono un'estensione non standard di ECMAScript e sono deprecate in QML. Utilizza invece i letterali template.

Esempio

import QtQuick

Item {
    property string multiLine: "first
second
third"

    property string multiLine2: 'first
second
third'
}

Per risolvere questo avviso, utilizzare i letterali template o, in alternativa, sostituire i caratteri di nuova riga con '\n':

import QtQuick

Item {
    property string multiLine: `first
second
third`
    property string multiLine2: `first
second
third`

    property string alternative: "first\nsecond\nthird"
    property string alternative2: "first\n" +
"second\n" +
"third"
}

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