Results 1 to 9 of 9

Thread: Error: Cannot assign to non-existent property

  1. #1
    Join Date
    Jun 2012
    Posts
    58
    Thanks
    13
    Qt products
    Qt4

    Question Error: Cannot assign to non-existent property

    main.qml:
    Qt Code:
    1. import QtQuick 2.0
    2.  
    3. Rectangle {
    4. height: 300
    5. width: 300
    6. color: "black"
    7.  
    8. Zero {
    9. m_ref.m_url: "something"
    10. }
    11. }
    To copy to clipboard, switch view to plain text mode 

    Zero.qml
    Qt Code:
    1. import QtQuick 2.0
    2.  
    3. Item {
    4. property alias m_ref: objZero
    5.  
    6. Rectangle {
    7. id: objZero
    8.  
    9. property url m_url
    10. }
    11. }
    To copy to clipboard, switch view to plain text mode 

    This gives an error:
    Qt Code:
    1. "m_url" Cannot assign to non-existent property
    2. m_ref.m_url: "something"
    3. ^
    To copy to clipboard, switch view to plain text mode 

    However i can use m_url inside Zero.qml anywhere (by qualifying with the correct id ofcourse) or alias it with the topmost Item of Zero.qml and use the alias in main.qml.
    Why using it the way shown above gives an error while the other methods (in the previous sentence) don't?

    {using Qt 5.1.0 beta and Rc both, Windows 7, QtQuick 2.0}

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Error: Cannot assign to non-existent property

    What you want to do is alias the m_url property

    Qt Code:
    1. import QtQuick 2.0
    2.  
    3. Item {
    4. property alias m_ref: objZero.m_url
    5.  
    6. Rectangle {
    7. id: objZero
    8.  
    9. property url m_url
    10. }
    11. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. import QtQuick 2.0
    2.  
    3. Rectangle {
    4. height: 300
    5. width: 300
    6. color: "black"
    7.  
    8. Zero {
    9. m_ref: "something"
    10. }
    11. }
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  3. #3
    Join Date
    Jun 2012
    Posts
    58
    Thanks
    13
    Qt products
    Qt4

    Default Re: Error: Cannot assign to non-existent property

    yes, i've mentioned that i know that in
    However i can use m_url inside Zero.qml anywhere (by qualifying with the correct id ofcourse) or alias it with the topmost Item of Zero.qml and use the alias in main.qml.
    part of my question.

    However, could you please explain why the other way (the one which given an error) does not work?

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Error: Cannot assign to non-existent property

    property type alias is for getting another name for an existing property. like a pointer or reference.
    objZero is not a propery, it is a value (of the id property of that element).

    Cheers,
    _

  5. #5
    Join Date
    Jun 2012
    Posts
    58
    Thanks
    13
    Qt products
    Qt4

    Default Re: Error: Cannot assign to non-existent property

    I think I'm missing your point; it's still not clear.

    I can have a property alias to an id, which I think is perfectly legal. That is how we expose the inner level sub-objects. For instance in this case I can use objZero in main.qml to refer to any property of inner Rectangle that was already present in it ie., not added additionally in Zero.qml. Eg

    main.qml:
    Qt Code:
    1. import QtQuick 2.0
    2.  
    3. Rectangle {
    4. height: 300
    5. width: 300
    6. color: "black"
    7.  
    8. Zero {
    9. m_ref.x: 0 //ok, as "x" existed in item Rectangle before it was used in Zero.qml
    10. m_ref.color: "blue" //ok, as "color" existed in item Rectangle before it was used in Zero.qml
    11. m_ref.url: "something" //ERROR, "url" did not exist in item Rectangle before it was used in Zero.qml..I added this and is hence unavailable
    12. }
    13. }
    To copy to clipboard, switch view to plain text mode 

    What does not work is any new property addition in Zero.qml to the inner Rectangle. Here property url m_url was added to the inner Rectangle in Zero.qml. This is not retrieved by the alias in main.qml. Why?

    (Putting it in a generic way, any new property addition to an inner object/sub-object is not retrieved by the alias)

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Error: Cannot assign to non-existent property

    Ah, I see.

    I wasn't aware that one could do that for built-in properties, I've always made the properties themselves available using alias.

    Accessing an inner element is breaking encapsulation, I think it is better to consider anything that is not on the top level element to be "private" to the custom component.

    Cheers,
    _

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

    Default Re: Error: Cannot assign to non-existent property

    Does it work if you assign the value in Component.onComplete handler of the Zero element?
    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.


  8. #8
    Join Date
    Jun 2012
    Posts
    58
    Thanks
    13
    Qt products
    Qt4

    Default Re: Error: Cannot assign to non-existent property

    Does it work if you assign the value in Component.onComplete handler of the Zero element?
    Yes it does.

    Could you tell me why? m_ref is already well formed when Zero {} is used in main.qml (which is why I can use any property which is present in Rectangle before its addition as a subObject inside Zero.qml.)

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

    Default Re: Error: Cannot assign to non-existent property

    Quote Originally Posted by ustulation View Post
    m_ref is already well formed when Zero {} is used in main.qml
    Apparently, it is not. Properties are assigned as the parser goes through the definition. Since the internal object has not yet been fully initiated (meaning that its custom properties are not yet created) the binding fails.
    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.


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

    ustulation (3rd July 2013)

Similar Threads

  1. Replies: 1
    Last Post: 8th September 2012, 06:56
  2. Replies: 0
    Last Post: 20th February 2012, 13:52
  3. QFileDialog 'Save As' to non-existent directory
    By mclark in forum Qt Programming
    Replies: 2
    Last Post: 9th September 2010, 23:32
  4. Linker error when creating custom Property Browser components
    By stefanadelbert in forum Qt Programming
    Replies: 1
    Last Post: 29th March 2010, 04:50
  5. Segmentation error at a simple return this->property ?
    By Daimonie in forum Qt Programming
    Replies: 6
    Last Post: 18th February 2009, 11:41

Tags for this Thread

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.