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
Forum Updated to NodeBB v4.3 + New Features

Using null in QML

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
4 Posts 3 Posters 6.8k 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 23 Jan 2020, 21:30 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
    • F Offline
      F Offline
      fcarney
      wrote on 23 Jan 2020, 22:20 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 23 Jan 2020, 22:47
      0
      • F fcarney
        23 Jan 2020, 22:20

        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 23 Jan 2020, 22:47 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...

        O 1 Reply Last reply 24 Jan 2020, 15:20
        0
        • C Circuits
          23 Jan 2020, 22:47

          @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...

          O Offline
          O Offline
          ODБOï
          wrote on 24 Jan 2020, 15:20 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

          1/4

          23 Jan 2020, 21:30

          • Login

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