Unsolved Validators in QML
-
@dheerendram
I have one text box on which i want to store two things on certain conditions:- Time (mm:ss)
- Integer values.
So i need to apply validators for this. So how to achieve two validators in one text box.
TextField{ id:text_area font.pixelSize:fontSize text:btn_text color:btn_text_color anchors.centerIn: parent width:root.width*0.9 height:root.height horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter inputMethodHints: Qt.ImhDigitsOnly validator: DoubleValidator{ top: top_value bottom:bottom_value }
}
-
You can use conditional operator and define the validators with ids.
e.g
IntValidator {id:three;bottom: 11; top: 31;}
IntValidator {id:four;bottom: 40; top: 50;}
property int val:1validator:val===0?three:four
-
I used conditional operator like this:
validator: val===0?RegExpValidator:DoubleValidator
But it is showing an error.
-
show me what are these RegExpValidator:DoubleValidator ?
-
@Shubham-Gupta
you'll have to read up on the Conditional OperatorIt reqiuers 2 expression after the ? your examply only has 1forget everything, it's to damn early in the morning.
-
What?
I din get your words. -
Please paste your code here. You need to use ternary operator. You may be doing in some mistake. Hence requested paste the code.
-
validator: val===0?DoubleValidator{ top: top_value bottom:bottom_value} : RegExpValidator{regExp: ""}
I am trying to make regular exp for accepting time(mm:ss).
But its showing an error. -
what is the error ?
-
Hi dheerendra
In qml there are three validators- IntValidator
- DoubleValidator
- RegExpValidator
If i want to store text like 2:30 (mm:ss). So which validator will work.
If RegExpValidor is used, so what will be the regular expression for this syntax (mm:ss). -
Use RegExpValidator. Did you check the google for regular expression for mm:ss ? It should help.
-
solved.
thanks -
Good. Move the case to "Solved" state. It helps others as well.