Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-16571 Resolve QtScript behavior that reflects implementation of old ("classic") back-end
  3. QTBUG-17375

QtScript overloads comparison operator == for QObject and QVariant wrappers

    XMLWordPrintable

Details

    • Sub-task
    • Resolution: Invalid
    • P2: Important
    • None
    • Qt Script
    • None

    Description

      If you create two QObject wrapper objects (using QScriptEngine::newQObject()) for the same C++ object, you'll get two distinct JS objects. This means that, according to ECMA-262, operator == should return false, because it compares the JS object references – nothing else. There is no way to overload operators in ECMAScript.

      But QtScript does "magic" comparison when QObject and QVariant wrappers are involved, so that if the wrappers contain the same value, operator == returns true. This is also true for the C++ API (QScriptValue::equals()).

      This requires some hooks/hacks in the VM that are not so nice. We'd like to drop this behavior, and introduce e.g. QObject.prototype.equals() if necessary.
      Unfortunately QML also relies on this behavior. But if QML (and other applications) want operator == to work for wrapper objects, they should ensure that there's a one-to-one relationship between wrappers and real objects.

      Attachments

        Issue Links

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

          Activity

            People

              kenthans Kent Hansen (Inactive)
              kenthans Kent Hansen (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes