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

Empty String in JS is Converted to null QString in C++

    XMLWordPrintable

Details

    Description

      class MyClass: QObject {
      Q_OBJECT
      public:
      Q_INVOKABLE void testEmpty(QString s) {
          Q_ASSERT(!s.isNull());
      }
      Q_INVOKABLE void testUndefined(QString s) {
          Q_ASSERT(is.isNull());
      }
      
      };
      

      In JS:

      var obj = new MyClass();
      obj.testEmpty("");
      obj.testUndefined(undefined);
      

      Expected:

      • "" is converted to an empty, but non-null QString object
      • undefined is converted to empty AND null QString object

      Observed:

      • QString is null in both cases

      The QString documentation says explicitly:

      QString().isNull();             // returns true
      QString("").isNull();           // returns false
      QString("abc").isNull();        // returns false
      

      Therefore the current conversion behavior is not intuitive.

      Attachments

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

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            rweickelt Richard Weickelt
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes