[Qt-qml] Calling slots with binding
aaron.kennedy at nokia.com
aaron.kennedy at nokia.com
Wed Jun 30 15:43:29 CEST 2010
Hi,
Bindings are intentionally unidirectional. As a binding can be a complex expression there is no way for us to automatically reverse it.
In the specific case you describe you could us a property alias.
Rectangle {
property alias title: myChild.title
Child {
id: myChild
}
}
Aliases are not bindings. Instead reading and writing to the title property of the rectangle is internally translated into reading and writing the title property of the Child.
Cheers,
Aaron
On 30/06/2010, at 11:01 PM, "ext Cristian Daniel Stamateanu" <cristi.qt at gmail.com> wrote:
> Ok, here is what I found, it seems that using bindings in QML, values
> are transfered to child components but when changed inside child the
> value is not sent back to the parent:
>
> //Parent.qml
> Rectangle{
> property string title: "initial value"
> id: root
>
> Child{
> title: root.title
> }
> }
>
> //Child.qml
> Rectangle{
> property string title
> id:child
> ...
> //JS script
> {
> child.title = "Child modified value";
> // I expected this to reflect back in parent or
> // whatever component was bound to it
> }
> ...
>
> }
>
> Is this normal? Is there a workaround
>
> Regards,
> Cristi
>
> Cristian Daniel Stamateanu wrote:
>> Thanks Kent, You were right on both counts. I don't need a QScriptValue
>> and the value is not sent from qml for some reason. I will investigate
>> further.
>>
>> BR.
>> Cristian Stamateanu
>>
>> On Tue, 29 Jun 2010 18:39:36 +0300, Kent Hansen <kent.hansen at nokia.com>
>> wrote:
>>
>>> Hi,
>>>
>>> On 29. juni 2010 16:58, ext Cristian Daniel Stamateanu wrote:
>>>> Hello,
>>>>
>>>> I have the following problem : I have a class declaring the following
>>>> slot:
>>>>
>>>> void RssFeedManager::addFeedEx(const QScriptValue& name,const
>>>> QScriptValue& address )
>>>> {
>>>> bool nameIsString = name.isVariant();
>>>> QString str = name.toString();
>>>> ...
>>>> }
>>>>
>>>> and I am calling this slot from QML
>>>>
>>>> This works ok:
>>>> feedManager.addFeedEx( "whatever", addFeedView.address );
>>>>
>>>> while using a binding to a property declared in addFeedView like
>>>> property string name;
>>>>
>>>> feedManager.addFeedEx( addFeedView.name, addFeedView.address );
>>>>
>>>> is not working.
>>>> In the c++ side I am getting a string only it is an empty one.
>>>>
>>>> Any thoughts?
>>>>
>>>
>>> Have you checked that the name is indeed non-empty on the JS side?
>>> Does it work if you declare the slot as taking a QString argument (why
>>> do want to receive it as a QScriptValue)?
>>> What type is the script value, is it an object? If so, does
>>> QScriptValue::toVariant() return anything? QML has a special "hook" to
>>> allow converting a script value to a variant, but no hook for the
>>> toString case AFAICT.
>>>
>>> Regards,
>>> Kent
>>> _______________________________________________
>>> Qt-qml mailing list
>>> Qt-qml at trolltech.com
>>> http://lists.trolltech.com/mailman/listinfo/qt-qml
>>
>>
>
> _______________________________________________
> Qt-qml mailing list
> Qt-qml at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-qml
More information about the Qt-qml
mailing list