Re: [Interest] QML defining an object property

2021-06-02 Thread Alexander Dyagilev

Thanks.

On 6/1/2021 10:52 AM, Pierre-Yves Siret wrote:



Le lun. 31 mai 2021 à 19:59, Alexander Dyagilev > a écrit :


Hello,

Am I right that this is not possible in QML?

readonlypropertyvarmainTbImg:{
    up:"some string",
up_check:"some another string"
}


The problem is that QML doesn't know how to parse it,  it can't know 
if it's a JS statement or a JS object definition. To disambiguate it 
you can either write:


    readonly property var mainTbImg: ({
        up: "some string",
        up_check: "some another string"
    })

or :

    readonly property var mainTbImg: {
        "up": "some string",
        "up_check": "some another string"
    }

Encompass the declaration with parenthesis or the property names with 
double quotes.
___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest


Re: [Interest] QML defining an object property

2021-06-01 Thread Pierre-Yves Siret
Le lun. 31 mai 2021 à 19:59, Alexander Dyagilev  a
écrit :

> Hello,
>
> Am I right that this is not possible in QML?
>
> readonly property var mainTbImg: {
> up: "some string",
>  up_check: "some another string"
> }
>

The problem is that QML doesn't know how to parse it,  it can't know if
it's a JS statement or a JS object definition. To disambiguate it you can
either write:

readonly property var mainTbImg: ({
up: "some string",
up_check: "some another string"
})

or :

readonly property var mainTbImg: {
"up": "some string",
"up_check": "some another string"
}

Encompass the declaration with parenthesis or the property names with
double quotes.
___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest


Re: [Interest] QML defining an object property

2021-05-31 Thread Jérôme Godbout
Here is the example you can try (if the link ever die):

import QtQuick 2.7
import QtQuick.Controls 2.3

Rectangle
{
color: "red"
anchors.fill: parent

Row
{
Button
{
text: "test"
onClicked:
{
a_.allo['toto'] = "changed";
a_.alloChanged(); // require for value to be considered
a_.allo['toto'] = "ignored";
}
}

Button
{
id: b_
text: "test2"
onClicked:
{
text = "yaga";
}
}
}

Text {
id: a_
text: "Test: " + allo['toto'] + " Test2: " + allo["baba"]
font.pixelSize: 50
color: "white"
anchors.centerIn: parent
readonly property var allo: { "toto": "yeah", "baba": b_.text}
}
}

Jérôme Godbout, B. Ing.

Software / Firmware Team Lead
O: (418) 682-3636 ext.: 114
C: (581) 777-0050
godbo...@dimonoff.com<mailto:godbo...@dimonoff.com>
[signature_969455327]<https://www.dimonoff.com/>
dimonoff.com<https://www.dimonoff.com/>
1015 Avenue Wilfrid-Pelletier,
Québec, QC G1W 0C4, 4e étage


From: Interest  on behalf of Jérôme Godbout 

Date: Monday, May 31, 2021 at 3:00 PM
To: Alexander Dyagilev , interest@qt-project.org 

Subject: Re: [Interest] QML defining an object property
This should be working (at least into 5.15.x). Binding value into the object 
should emit the changed normally.

Take care if you want a binding to react to values changed inside the 
dictionary/object inside you property, you will need to emit the change on the 
property.

Normally an easy way is to copy the value and modify it and reassign it. But 
here since you are readonly you cannot do that.

Try to emit changed when a dependencies is modified or when you set the value 
inside it.

Ex:
Function myEditFct()
{
mainTbImg[‘up’] = “popo”;
mainTbImgChanged(); // this is the missing piece often forgotten
}

Here an example that display the behavior
https://tinyurl.com/yg7ykwc4



From: Interest  on behalf of Alexander 
Dyagilev 
Date: Monday, May 31, 2021 at 1:57 PM
To: interest@qt-project.org 
Subject: [Interest] QML defining an object property

Hello,

Am I right that this is not possible in QML?

readonly property var mainTbImg: {

up: "some string",

up_check: "some another string"

}
___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest


Re: [Interest] QML defining an object property

2021-05-31 Thread Jérôme Godbout
This should be working (at least into 5.15.x). Binding value into the object 
should emit the changed normally.

Take care if you want a binding to react to values changed inside the 
dictionary/object inside you property, you will need to emit the change on the 
property.

Normally an easy way is to copy the value and modify it and reassign it. But 
here since you are readonly you cannot do that.

Try to emit changed when a dependencies is modified or when you set the value 
inside it.

Ex:
Function myEditFct()
{
mainTbImg[‘up’] = “popo”;
mainTbImgChanged(); // this is the missing piece often forgotten
}

Here an example that display the behavior
https://tinyurl.com/yg7ykwc4



From: Interest  on behalf of Alexander 
Dyagilev 
Date: Monday, May 31, 2021 at 1:57 PM
To: interest@qt-project.org 
Subject: [Interest] QML defining an object property

Hello,

Am I right that this is not possible in QML?

readonly property var mainTbImg: {

up: "some string",

up_check: "some another string"

}
___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest