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

QML url property with empty value evaluates to true in JS boolean context

    XMLWordPrintable

Details

    Description

      My expectation is that in Javascript code, a URL will evaluate in a boolean context just like a string would, i.e. the empty URL would evaluate to false like the empty string does. I think there was some version of Qt where this was the case, but I tested back to 5.7 and did not find this to be true, so I'm not sure if it's a regression.

      Reproduced as such:

      import QtQuick 2.0
      
      Rectangle {
          property url myUrl: ""
      
          function update() {
              if (myUrl)
                  text.text = "evaluates to true";
              else
                  text.text = "evaluates to false";
          }
      
          color: "white"
          onMyUrlChanged: update()
          Component.onCompleted: update()
      
          Text {
              id: text
      
              color: "black"
          }
      }

      Attachments

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

        Activity

          People

            qtqmlteam Qt Qml Team User
            forest Forest Bond
            Votes:
            14 Vote for this issue
            Watchers:
            10 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes