Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-138091

False Warning for Optional Chaining/Nullish Coalescing with QVariant/QVariantMap in QML

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • Not Evaluated
    • None
    • 6.8.3
    • QML: Compiler
    • None

    Description

      When using the optional chaining (?.) and nullish coalescing (??) operators to safely access properties of QVariant/QVariantMap type in QML, false warnings are reported by the code analyzer:

      Cannot load property variable from dict with type QVariant Cannot load property variable from QVariant

      Despite these warnings, the code runs correctly at runtime and behaves as expected—the operators correctly guard against null/undefined access.

      Example Code:

      Item {
          property var dict: ({variable: "value"})
          readonly property string dictVariable: dict?.variable ?? "" // Warning: Cannot load property variable from dict with type QVariant     
      
          Component.onCompleted: {
              console.log(dict?.variable ?? "") // Warning: Cannot load property variable from QVariant
          }
      } 

      The issue does also occur when the type is explicitly annotated as QVariantMap on the C++ side and exposed with Q_PROPERTY

       

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            qtqmlteam Qt Qml Team User
            romain.donze Romain Donzé
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes