convert textfield text in to double or int



  • I need to do some mathematical operation based on textfield.

    For ex:

    textfield:{
    id:tf1
     text:""
    ontextchanged{
    
    tf2.text=(tf1.text*50)/25
    }
    }
    textfield:{
    id:tf2
     text:""
    
    }
    

    Note: We enter real value (60.00) in tf1 and also we get real value(80.00) in tf2

    If i use the same calculation, i get output as zero.

    In that any text changed in textfield1 will automatically refeclt to the textfield2 and autocalculated value will be displayed in textfield2.


  • Moderators

    @eswar I think you should first convert it to float using parseFloat then perform calculations on it. You can find many example of JS related to it.



  • If i use phraseFloat , l get ouput like this
    qml: NaN
    qml: NaN


  • Moderators

    How did you use it ?



  • @eswar
    Its working as per your need.

    I didn't find any time zero as per you are saying...

    TextField{
        id:tf1
        text:""
        width: 50
        onTextChanged: {
            tf2.text=(tf1.text*50)/25
            console.log(tf2.text);
        }
        }
        TextField{
        id:tf2
        text:""
        x:tf1.width + 50
        }
    


  • In that above method , based on the textfield1 the data in the textfield 2 is changed. In that textfield 2 , i set validator. The value lies in between 0 to 1000 will be apper in tf2. I entered higher value, the tf2 value will appear any values . The tf2 validator will not validate tf2 data. In tf2 the value only 0 to 1000 will be appear , if i enter any value in tf1. How can i achieve that?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.