Solved Parse problem with RegExpValidator in large binding
-
Sample code:
validator: { if (rootItem.validator == 'test') return RegExpValidator {} else if (rootItem.validator == 'int') return IntValidator {} else return undefined }
I always get
Expected token ';'
onreturn RegExpValidator {}
andExpected token '}'
onelse if (rootItem.validator == 'int')
I dont get problems if a string is returned (It just says that I can't assign a QString to a QValidator).
-
Hi and welcome to devnet
AFAIK it should be:
return RegExpValidator {regExp: /''/}
-
@SGaist Thanks for your answer.
ButRegExp
works well if I used it as a simple binding (no curly brackets and an inline if..else statement).
And it is supported as the docs says: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions -
But you are using a RegExpValidator which is a QML type and the documentation of the regExp property explicitly state that you should pass a regular expression in JS syntax.
-
@SGaist I made an edit to the code (even though
RegExp
works for me). I get the same error with the new code. -
Ok, I think I misunderstood your original setup.
A cleaner way to do that would be to have a validatorName property on your item and you change the validator accordingly. You can then manipulate that property from your rootItem for example.
WARNING not tested
YourItem { id: yourItem property str validatorName: "test" onValidatorNameChanged: { if (validatorName == "int") validator = intval; else if (validatorName == "test") validator = regex; // etc } IntValidator { id: intval } RegExpValidator { id: regexp; regExp: /""/ } }
-
@SGaist Thanks a dozen! It worked! :)