← Back to team overview

ubuntu-phone team mailing list archive

Re: QML How can i store the value an user enters in a variable?

 

(Reinserted in CC the ML, my fault I replied only to you)

On Wed, Jul 09, 2014 at 12:14:00AM +0100, diogo wrote:
> 
> Hi Riccardo
> 
> Thanks for your help.
> 
> What i want to is like this. I have 48 textfields divided in 6 groups of 12
> fields each. i want the user to fill them in with numbers so i can do this:
> the sum of the first group multiplies with the multiplication of the 2 and 3
> group (optional) or with the sum of the 4th group that create var x. then
> the 5th and 6th group create a new var by doing the 5th group x 6th group
> divided by 60, that will create a new var T. After that i want to do X x T
> the result of that create var Y and then var Y divided by 1000 will create
> var K and to finish off var K x 0.101 that will create the and result that i
> want to display to the user, can i do that using the ID's lik q1??

Hi Diogo,
probably the best way to achieve what you want is to use an array with 6
sub-array (array[6][12]).

You can declare your array in the MainView, doing something like this:

property var arrayInt: [[], [], [], [], [], []]

Then, whenever a user insert a value in a TextField, you can save it:

onActiveFocusChanged: {
    if (!focus) {
        arrayInt[0][0] = text;
    }
}
                                                                                }
changing the index of the array following your needs.
At the end, when you want to calculate the result, you can use the array.

Of course you can use id to access value, but using an array is IMO easier and
less messy.

Regards,



> On 08-07-2014 23:57, Riccardo Padovani wrote:
> >On Tue, Jul 08, 2014 at 09:47:24PM +0100, diogo wrote:
> >
> >Hi Diogo,
> >
> >>How can i store the value an user enters in a variable?
> >you have a lot of different possible implementations, depending on what you try
> >to achieve.
> >
> >>can i use the id to later use and make the sum or the multiplication?? If
> >>yes then and how??
> >Yes, if you want to access directly to the value, without using an external
> >variable, you can do something like this:
> >
> >function calculate(){
> >     int result = parseInt(q1.text, 10)
> >}
> >
> >You can access to all proprieties of an object using idValue.propriertyName
> >
> >Also, looking to your code, could you suggest to you to start from a simple
> >tutorial?
> >
> >You can find one here:
> >http://developer.ubuntu.com/apps/qml/tutorial/building_your_first_qml_app/
> >
> >Also, on Ubuntu we use units.gu() as unit. Take a look to
> >http://developer.ubuntu.com/api/qml/sdk-14.10/Ubuntu.Components.Units/
> >
> >If you have any doubt, ask here or join #ubuntu-app-devel on Freenode :-)
> >
> >Regards,
> 

-- 
Riccardo Padovani
www.rpadovani.com


References