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

QML "instanceof" and "as" fail with "QtQuick.url" type

    XMLWordPrintable

Details

    • d9d1c1fb5 (dev), 6df089674 (6.9)

    Description

      Using the instanceof operator with qmls url type never seems to work. I have tried using both `Addressable` and the new `Assertable` `ValueTypeBehavior` pragma values and while the as operator works if in Addressable mode instanceof never works.

      It does work with string and rect property types though, I created a simple test app testing instanceof, as and typeof for url, string and rect and only url does not work as I would expect leading me to think there is an issue here:

      root.urlProperty instanceof QtQuick.url       // fails
      root.stringProperty instanceof QtQuick.string // succeeds
      root.rectProperty instanceof QtQuick.rect     // succeeds

      See the attached Main.qml file for the full code examples.

      Note, while the as cast succeeds with pragma ValueTypeBehavior: Addressable enabled it will print the following warning so I don't see that as a win either:

      qt.qml.coercingTypeAssertion: qrc:/qt/qml/url-instance-of/Main.qml:58: Coercing a value to QML/url using a type assertion. This behavior is deprecated. Add 'pragma ValueTypeBehavior: Assertable' to prevent it.

      Attachments

        1. image-2024-10-18-11-15-18-775.png
          57 kB
          Ollie Dawes
        2. Main.qml
          3 kB
          Ollie Dawes
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes