2012-12-19 38 views

回答

5

您既可以在目標頁面上創建屬性,也可以創建Java腳本函數來執行此操作。如果您想在分配之前驗證或執行任何其他操作,則應使用Java腳本函數。

Page { 
    //targetPage 

    property string userid //you can also use alias here 

    function initialize(id) { 
     userid = id 
     //you can also set property of controls here 
    } 
} 

調用它在網頁上這樣

targetPageid.userid = "user id" 

OR

targetPageid.initialize("user id") 
+0

我試圖從具有導航窗格中我的主頁,在poptransition訪問主頁上的功能我需要調用網頁的方法,我嘗試按照你的方法,但沒有工作。它顯示找不到targetPageid。我已經宣佈targetPageid爲主頁ID。我必須包含任何其他內容才能在我的主頁上訪問它嗎? – Gamerlegend

0

cpp

qml->setContextProperty("MyApp",this); 

創建一個對象,然後調用使用此對象的方法。我叫一個按鈕的方法我main.qml

Button{ 
     id : button 
     text : "Connect" 
     onClicked: 
      { 
       MyApp.PostData("46565652","sotho") 
      } 
     horizontalAlignment: HorizontalAlignment.Center 
    }  
相關問題