2011-07-13 8 views
2

私はQMLにコードスニペットを持っていますが、これはscreen.textで正規表現 "Calling"を探し、見つからなければ変更しますscreen.text.残念ながら、ドキュメントはQML/QString documentationでは明確ではありません。はQMLのQstring /文字列にある可能性のあるもの(regexp)を含んでいます

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 
     } 
    } 

私が手にエラーがある:

file:///home/arnab/workspace/desktop/examples/cellphone.qml:127: TypeError: Result of expression 'screen.text.toString().startsWith' [undefined] is not a function.

答えて

3

をハンドラでJavascript関数を使用する必要があります:

 onClicked:{ 
     var patt = /^Calling/; 
     if(patt.test(screen.text)) 
      return; 
     else 
      screen.text = "Calling " + screen.text 
    } 
0

機能 "のstartsWith" は標準機能ではありませんので。あなたはQML JSでプロトタイプを使用できるかどう

が言うことはできませんが、あなたは、このコードを使用します。ここで読むために

String.prototype.startsWith = function(str) 
{return (this.match("^"+str)==str)} 

のみ

if(screen.text.toString().match("^Calling")==screen.text.toString())

詳細:http://www.tek-tips.com/faqs.cfm?fid=6620

0

他の2つの回答と同様に、toString()QStringではなくJavaScript文字列を指定し、JavaScript文字列にはstartsWith()が含まれていません。表示された回避策の1つを使用します。

関連する問題