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

qmlcachegen generates invalid cpp when using ?.

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P1: Critical
    • None
    • 6.9.0
    • QML: Compiler
    • None
    • 5ff76ab872de6bae9766d52f4f794256ae9eeebf

    Description

      Initially we found that a source file from kdeplasma-addons failed to build:

      [   80s] /home/abuild/rpmbuild/BUILD/kdeplasma6-addons-6.3.80git.20250515T163246_36de84f9-build/kdeplasma-addons-6.3.80git.20250515T163246~36de84f9/build/applets/comic/.rcc/qmlcache/org.kde.plasma.comic_qml/ComicBottomInfo_qml.cpp:2343:27: error: ‘class QString’ has no member named ‘isUndefined’
      [   80s]  2343 | if (r2_4.isNull() || r2_4.isUndefined())
      

      The reason for that is that the referenced variable has (according to .qmltypes of the module) a type of QString, i.e. can't be null or undefined, so using the .? operator here is unnecessary, but not broken.

      Reproducer:

      import QtQuick
      
      Text {
      	id: root
      	property string mystr: "asdf"
      
      	// Warning: test.qml:10:10: Cannot convert from qlonglong to QJSPrimitiveValue [compiler]
      	// text: (root.mystr?.length > 0) ? root.mystr : ""
      	// Fails to build!
      	text: (root.mystr?.length) ? root.mystr : ""
      }
      

      Initially the build failure only happened on 32-bit platforms. The reason for that is that on 64-bit platforms, qmlcachegen was unable to generate cpp for the 64-bit length value used by the comparison.

      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
            vogtinator Fabian Vogt
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes