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

QML_CONSTRUCTIBLE_VALUE misbehaves on constructors taking QJSValue

    XMLWordPrintable

Details

    • d61c0ce1b (dev), 373cf5eae (dev), 11c6eff62 (6.8), b497a4391 (6.8)

    Description

      Consider:

      class VARIANT
      {
          Q_GADGET
          QML_VALUE_TYPE(variant)
          QML_CONSTRUCTIBLE_VALUE
          Q_PROPERTY(QDBusVariant value READ getValue)
      public:
          explicit VARIANT()
          {
          }
          Q_INVOKABLE explicit VARIANT(const QJSValue &_value)
              : value(_value.toVariant())
          {
              qDebug() << Q_FUNC_INFO << value.variant() << _value.toString();
          }
          operator QVariant() const
          {
              return value.variant();
          }
          operator QDBusVariant() const
          {
              return value;
          }
          Q_INVOKABLE QString toString() const
          {
              return value.variant().toString();
          }
      
          QDBusVariant getValue() const
          {
              return value;
          }
      
          QDBusVariant value;
          constexpr static const char *signature = "v";
      };
      

      Now assign to such a thing in QML:

      import QtQml
      import varianttype as DBus
      
      QtObject {
          property DBus.variant test: "abcdefg"
      }
      

      With versions prior to 6.8 this is just refused:

      Could not find any constructor for value type VARIANT to call with value QVariant(QString, abcdefg)
      QQmlApplicationEngine failed to create component
      qrc:/qt/qml/varianttype/Main.qml:5:27: Cannot assign value abcdefg to property test
      

      With 6.8 and later, the constructor is called, but with an "undefined" QJSValue. That's even worse.

      Attachments

        Issue Links

          For Gerrit Dashboard: QTBUG-130522
          # Subject Branch Project Status CR V

          Activity

            People

              ulherman Ulf Hermann
              ulherman Ulf Hermann
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews