2017-10-05 36 views
1

私はこの質問が何度も尋ねられたことを知っていますが、回答者のどれも私を助けないでしょう。私は2つのQMLファイルを持っています。最初のQMLファイルは、その中にマップを持っていると私は地図上押したときには、次のコードでウィンドウを開きます。別のQmlからQmlのプロパティから値を取得するには?

MouseArea{ 
    id: mouseArea 
    property var positionRoot: map.toCoordinate(Qt.point(mouseX, mouseY)) 
    anchors.fill: parent 
    onClicked: { 
      var component = Qt.createComponent("addAttribute.qml") 
      if (component.status === Component.Ready) { 
      var dialog = component.createObject(parent,{popupType: 1}) 
      dialog.show() 
     } 
    } 
} 

ウィンドウがlabeltextfieldbuttonを持っています。私が望むのは、最初のQMLファイルで作成したproperty(positionRoot)の値を取得することです。どうすればそれをすることができますか?

+1

は、第二のウィンドウにpositionRoot' 'と同じ型のプロパティを作成し、作成中に値を渡す - ' dialog.positionRoot2 = positionRoot; ' – folibis

+0

はどうもありがとうございました!! – Blinxen

答えて

0

@folibisのおかげでうまくいきました。追加が必要なコードは次のとおりです。

MouseArea{ 
     id: mouseArea 
     property var positionRoot: map.toCoordinate(Qt.point(mouseX, mouseY)) 
     anchors.fill: parent 
     onClicked: { 
       var component = Qt.createComponent("addAttribute.qml") 
       if (component.status === Component.Ready) { 
       var dialog = component.createObject(parent,{popupType: 1}) 
       dialog.sqlPosition = positionRoot 
       dialog.show() 
      } 
     } 
    } 

私の2番目のウィンドウでは、単にsqlPositionという新しいプロパティを作成します。たとえば:

Window { 
     id: secondWindow 
     property var sqlPosition 
    } 
関連する問題