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

Null pointers returned to QML are evaluated as TRUE in JS conditional statements

    XMLWordPrintable

Details

    Description

      Investigating a crash I discovered that null pointers returned to QML are able to pass conditional statements as true.

      class Something {...};
      Q_DECLARE_METATYPE(Something*)
      ...
      qRegisterMetaType<Something*>();
      ...
      Q_INVOKABLE Something* get() { return nullptr; }
      ...
      // in QML
      if (Obj.get()) // its true
      

      I don't think it is unreasonable to expect that a null pointer gets evaluated as null and therefore as false on the JS side. Yet regardless of whether it is or isn't a null pointer, it always passes and in the console it just says `QVariant(Something*)`

      Attachments

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

        Activity

          People

            shausman Simon Hausmann
            dgo dgo
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes