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

Compiler: Add support for Optional Chaining/Nullish Coalescing with QVariant/QVariantMap

XMLWordPrintable

    • Icon: Task Task
    • Resolution: Unresolved
    • Icon: P2: Important P2: Important
    • 6.12
    • 6.8.3
    • QML: Compiler
    • None

      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

       

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

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

              Created:
              Updated:

                There are no open Gerrit changes