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. Set property to undefined in QML

Set property to undefined in QML

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 3.2k Views
  • 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.
  • D Offline
    D Offline
    Developer123
    wrote on 15 Feb 2022, 12:52 last edited by Developer123
    #1

    Hello,

    I'd like to initialize a property to undefined, to indicate that the property has not been set yet (and check this later):

    property real somevar: undefined
    

    However, I get the error:

    Unable to assign [undefined] to double

    Any way to do this? Otherwise I need to create an extra variable somevarInitialized to know if it has been initialized already, and this seems counter productive. In javascript, one can just assign undefined freely.

    K 1 Reply Last reply 15 Feb 2022, 12:59
    1
    • D Developer123
      15 Feb 2022, 12:52

      Hello,

      I'd like to initialize a property to undefined, to indicate that the property has not been set yet (and check this later):

      property real somevar: undefined
      

      However, I get the error:

      Unable to assign [undefined] to double

      Any way to do this? Otherwise I need to create an extra variable somevarInitialized to know if it has been initialized already, and this seems counter productive. In javascript, one can just assign undefined freely.

      K Offline
      K Offline
      KroMignon
      wrote on 15 Feb 2022, 12:59 last edited by KroMignon
      #2

      @Developer123 said in Initialize property to undefined:

      In javascript, one can just assign undefined freely.

      AFAIK, you cannot set primary typed properties (like int, real) to undefined. I don't know anymore where I found this.
      If you want to use undefined you have to use var as property type:

      property var somevar: undefined
      

      It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

      D 1 Reply Last reply 15 Feb 2022, 13:01
      1
      • K KroMignon
        15 Feb 2022, 12:59

        @Developer123 said in Initialize property to undefined:

        In javascript, one can just assign undefined freely.

        AFAIK, you cannot set primary typed properties (like int, real) to undefined. I don't know anymore where I found this.
        If you want to use undefined you have to use var as property type:

        property var somevar: undefined
        
        D Offline
        D Offline
        Developer123
        wrote on 15 Feb 2022, 13:01 last edited by
        #3

        @KroMignon Perfect, thanks!

        1 Reply Last reply
        0

        1/3

        15 Feb 2022, 12:52

        • Login

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