本页内容

多行字符串

qmllint 将此警告类别拼写为[multiline-strings] 。

字符串中包含未转义的行结束符,该用法已弃用

发生了什么?

一个字符串跨越了多行。

为什么这有问题?

跨多行的字符串是 ECMAScript 的非标准扩展,在 QML 中已弃用。请改用模板字面量。

示例

import QtQuick

Item {
    property string multiLine: "first
second
third"

    property string multiLine2: 'first
second
third'
}

要解决此警告,请使用模板字面量,或者将换行符替换为 '\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.