Error: Cannot assign to non-existent property
main.qml:
Code:
import QtQuick 2.0
Rectangle {
height: 300
width: 300
color: "black"
Zero {
m_ref.m_url: "something"
}
}
Zero.qml
Code:
import QtQuick 2.0
Item {
property alias m_ref: objZero
Rectangle {
id: objZero
property url m_url
}
}
This gives an error:
Code:
"m_url" Cannot assign to non-existent property
m_ref.m_url: "something"
^
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}
Re: Error: Cannot assign to non-existent property
What you want to do is alias the m_url property
Code:
import QtQuick 2.0
Item {
property alias m_ref: objZero.m_url
Rectangle {
id: objZero
property url m_url
}
}
Code:
import QtQuick 2.0
Rectangle {
height: 300
width: 300
color: "black"
Zero {
m_ref: "something"
}
}
Cheers,
_
Re: Error: Cannot assign to non-existent property
yes, i've mentioned that i know that in
Quote:
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?
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,
_
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:
Code:
import QtQuick 2.0
Rectangle {
height: 300
width: 300
color: "black"
Zero {
m_ref.x: 0 //ok, as "x" existed in item Rectangle before it was used in Zero.qml
m_ref.color: "blue" //ok, as "color" existed in item Rectangle before it was used in Zero.qml
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
}
}
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)
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,
_
Re: Error: Cannot assign to non-existent property
Does it work if you assign the value in Component.onComplete handler of the Zero element?
Re: Error: Cannot assign to non-existent property
Quote:
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.)
Re: Error: Cannot assign to non-existent property
Quote:
Originally Posted by
ustulation
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.