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. Using null in QML
QtWS25 Last Chance

Using null in QML

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
4 Posts 3 Posters 6.7k 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.
  • C Offline
    C Offline
    Circuits
    wrote on last edited by
    #1

    Would it be considered bad practice in qml to initialize a var to null? For instance:

    property var X: null
    
    1 Reply Last reply
    0
    • fcarneyF Offline
      fcarneyF Offline
      fcarney
      wrote on last edited by
      #2

      I wouldn't think so.

      property var x: null
      property var y: undefined
      

      Note that null is not the same as undefined.

      C++ is a perfectly valid school of magic.

      C 1 Reply Last reply
      0
      • fcarneyF fcarney

        I wouldn't think so.

        property var x: null
        property var y: undefined
        

        Note that null is not the same as undefined.

        C Offline
        C Offline
        Circuits
        wrote on last edited by
        #3

        @fcarney Is it even necessary in the QML world? Can I just leave it uninitialized like so:

        property var X;
        

        and tbh, I am initializing it as null but I am never running null checks when I use it...

        ODБOïO 1 Reply Last reply
        0
        • C Circuits

          @fcarney Is it even necessary in the QML world? Can I just leave it uninitialized like so:

          property var X;
          

          and tbh, I am initializing it as null but I am never running null checks when I use it...

          ODБOïO Offline
          ODБOïO Offline
          ODБOï
          wrote on last edited by
          #4

          @Circuits said in Using null in QML:

          Is it even necessary in the QML world? Can I just leave it uninitialized like so:
          property var X;

          no, it is undefined if you let it uninitialized.you can test it

               property var undefinedVar
              Component.onCompleted: console.log(undefinedVar)
          // output  > qml: undefined
          
          
          1 Reply Last reply
          2

          • Login

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