Results 1 to 7 of 7

Thread: TypeError: Cannot read property 'length' of undefined in QML array

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2011
    Posts
    231
    Thanks
    141
    Thanked 6 Times in 5 Posts

    Default Re: TypeError: Cannot read property 'length' of undefined in QML array

    thankful to you, got the point now.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: TypeError: Cannot read property 'length' of undefined in QML array

    In situations such as this it is wise to use a Component.onCompleted handler to make sure the other method only gets executed when the object is fully constructed:

    javascript Code:
    1. Item {
    2. property var prop
    3. property var prop2
    4.  
    5. property bool __constructed: false
    6.  
    7. onPropChanged: {
    8. if(!__constructed) return
    9. doSomethingWith(prop2)
    10. }
    11. Component.onCompleted: {
    12. __constructed = true
    13. // do some other initial stuff
    14. }
    15. }
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    TheIndependentAquarius (12th June 2014)

  4. #3
    Join Date
    Apr 2011
    Posts
    231
    Thanks
    141
    Thanked 6 Times in 5 Posts

    Default Re: TypeError: Cannot read property 'length' of undefined in QML array

    wysota

    That was very helpful - much thankful to you too.

Similar Threads

  1. Replies: 1
    Last Post: 30th December 2013, 14:53
  2. read sqlite to array
    By vanduongbk in forum Newbie
    Replies: 3
    Last Post: 1st October 2013, 14:08
  3. Replies: 1
    Last Post: 1st July 2013, 14:27
  4. Replies: 0
    Last Post: 28th May 2012, 19:56
  5. read from file into array
    By obad in forum Qt Programming
    Replies: 1
    Last Post: 1st August 2010, 08:26

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.