Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Boolean properties, &&, and falsy values
Forum Updated to NodeBB v4.3 + New Features

Boolean properties, &&, and falsy values

Scheduled Pinned Locked Moved QML and Qt Quick
qmljavascript
2 Posts 2 Posters 1.1k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Buttink
    wrote on last edited by Buttink
    #1

    So I have code that looks like this

        property boolean isSomething: otherProp && someUndefinedProp // this happends to be undefined
    

    I looked this up and apparently this is a result of javascript's "&&" operator. It assumes the type of the falsy value. So because undefined is the falsy value, you get undefined back. This produces the following error when ran "Unable to assign [undefined] to bool". My question is basically, should this happen? I feel like the qml type system should be able to convert this to boolean if the value itself is falsy. I could see an argument against this because it is no longer type safe, but at the same time its javascript so I don't know. Granted, I could just make the property var. However, that only gets me so far, if a qml component wants bool I still have to make sure its not equal to false. Anyway, I was just wondering peoples thoughts

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      I think this is just the kind of oddities one has to live with when one lies in bed with a weird language like Javascript. ^_^

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved