이 페이지에서

중복된 선택적 체이닝

qmllint에서는 이 경고 범주를 ‘ [redundant-optional-chaining] ’로 표기합니다.

중복된 선택적 체이닝

무슨 일이 발생했나요?

일부 조회에서 불필요한 경우 선택적 연쇄가 사용되었습니다. 이는 열거형 값을 조회할 때나, null 또는 undefined 가 될 수 없는 베이스에 대한 조회를 수행할 때 발생할 수 있습니다.

왜 문제가 될까요?

선택적 조회(optional lookup)는 일반 조회에서는 필요 없는 런타임 검사를 수행해야 합니다. 이러한 추가 명령어는 툴링에 의해 항상 중복으로 판단되어 최적화될 수 있는 것은 아닙니다. 결과적으로 런타임 성능에 추가적인 부담을 주고 프로그램을 불필요하게 부풀리게 됩니다.

또한, 이 경고는 체인 내의 잘못된 베이스에서 선택적 조회가 수행되었음을 시사할 수 있습니다. 보다 구체적인 예시는 다음 섹션을 참조하십시오.

예시

// Main.qml
import QtQml

QtObject {
    // Main will either be resolved and always work, or throw an exception or fail to compile
    enum E { A, B, C }
    property int i: Main?.A

    // A url cannot be null or undefined
    property url u: ""
    property string s: u?.toString()

    // Did you mean to make the second lookup optional?
    property int i: Safe?.Unsafe.i
}

이러한 경고를 수정하려면 중복되는 선택적 조회들을 필수 조회로 대체하십시오:

// Main.qml
import QtQml

QtObject {
    enum E { A, B, C }
    property int i: Main.A

    property url u: ""
    property string s: u.toString()

    property int i: Safe.Unsafe?.i
}

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