I have a code snippet in QML which should look for the regexp "Calling" in screen.text, and if it is not found, only then does it change the screen.text.Unfortunately, the documentation is not clear in QML/QString documentation.
Button{
id: call
anchors.top: seven.bottom
anchors.left: seven.left
text: "Call"
width: 40
onClicked:{
if(screen.text.toString().startsWith("Calling" , false))
return;
else
screen.text = "Calling " + screen.text
}
}
The error I get is :
file:///home/arnab/workspace/desktop/examples/cellphone.qml:127: TypeError: Result of expression 'screen.text.toString().startsWith' [undefined] is not a function.
You have to use Javascript functions in the handler:
onClicked:{
var patt = /^Calling/;
if(patt.test(screen.text))
return;
else
screen.text = "Calling " + screen.text
}
Because function "startsWith" is not standard function.
Can't say if you can use prototypes in QML JS but you use this code:
String.prototype.startsWith = function(str)
{return (this.match("^"+str)==str)}
or only
if(screen.text.toString().match("^Calling")==screen.text.toString())
more to read here: http://www.tek-tips.com/faqs.cfm?fid=6620
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With