2016-09-30 11 views
1

SwipeViewのアニメーションが終了した後、UIからパラメータを指定してC++クラスメソッドを呼び出す必要があります。QMLアニメーションの終了後にC++関数を呼び出す

main.ui

ApplicationWindow { 
visible: true 
width: 640 
height: 480 
title: qsTr("Hello World") 

SwipeView { 
    id: swipeView 
    anchors.fill: parent 

    Page1 { 
     id: page1 
    } 

    Page2{ 
     id: page2 
    } 
} 

XOR { 
    id: xor 
    onXorEnded: { 
     //swipeView.setCurrentIndex(0) 
    } 
    onQChanged: { 
     page2.bar.value = xor.getq() 
    } 
} 

}

Page1Form.ui.qml

Page1Form { 



kpButton.onClicked: { 
    kpDialog.visible = true 
} 

xorButton.onClicked: { 
    swipeView.setCurrentIndex(1) 
    xor.crypt(file_path.text, key_path.text, out_path.text) 
} 

fpButton.onClicked:{ 
    fpDialog.visible = true 
} 


FileDialog { 
    id: fpDialog 
    onAccepted: { 
     file_path.text = fpDialog.fileUrl 
    } 
} 

FileDialog { 
    id: kpDialog 
    onAccepted: { 
     key_path.text = kpDialog.fileUrl 
    } 
} 
} 

はxorButton.onClickedにスワイプビュー端部のアニメーションの前に開始XOR演算のように思えます。どのように機能するようになりました:あなたは、インデックスの変化にあなたの行動をバインドすることができます回避策としてImgur

+0

スワイプビューは、アニメーションや独自のアニメーションを設定する方法を提供しないため、簡単な方法はありません。これは組み込みのQMLコントロールの典型であり、その理由は何も使用していないためです。あなたはそれが提供するものを解決するか、機能性と柔軟性を望むならあなた自身のコントロールを行います。 – dtech

+0

あなたの問題は、あなたの 'xor.crypt'メソッドが同期している(すべてのデータが計算された後にのみ返る)メソッドなので、あなたが望む動作をさせるためには非同期にする必要があります。 – GrecKo

答えて

4

を:

xorButton.onClicked: { 
    swipeView.setCurrentIndex(1) 
} 


SwipeView { 
    id: swipeView 
    onCurrentItemChanged: { 
     if(currentIndex == 1) 
      xor.crypt(file_path.text, key_path.text, out_path.text) 
    } 
} 

しかし、いずれにせよ、それはアニメーションの最後ではない発射します。

もう1つの回避策として、StackViewを使用できます。アニメーションを制御するプロパティがさらにあります。このコントロールのもう1つの利点は、ユーザーがそれを期待していないときにスワイプできないことです。あなたの場合、ユーザーはそれをスワイプできるだけです。もう1つの利点は、必要のないときにページがメモリを占有しないということです。

import QtQuick 2.7 
import QtQuick.Window 2.2 
import QtQuick.Controls 2.0 


Window { 
    visible: true 
    width: 800 
    height: 800 
    StackView { 
     id: view 
     anchors.fill: parent 
     initialItem: page1 
     onBusyChanged: { 
      if(!busy && currentItem.objectName == "page2") 
       currentItem.run(); 
     } 
    } 
    Component { 
     id: page1 
     Rectangle { 
      color: "green" 
      objectName: "page1" 
      Button { 
       anchors.centerIn: parent 
       text: "swipe me" 
       onClicked: 
        view.push(page2) 
      } 
     } 
    } 

    Component { 
     id: page2 
     Rectangle { 
      color: "yellow" 
      objectName: "page2" 
      function run() { sign.visible = true; } 

      Rectangle { 
       id: sign 
       anchors.centerIn: parent 
       width: 100 
       height: 100 
       radius: 50 
       color: "red" 
       visible: false 
      } 
     } 
    } 

} 
+0

ありがとうございます:) –

関連する問題