Qt Quick UI (QML) で作成された UI を C++ コード (関数など) と通信 (対話) させる方法を見つけようとして、過去数時間 Qt のドキュメントを読んでいました。
ここで 5 つまたは 6 つの同様の質問を読みましたが、ちょっと混乱しています。どこから始めればよいか、最初に何をすべきかを理解するのに問題があります。誰かが時間をかけて、これを機能させるために必要な手順をリストしていただければ幸いです。
私がこれまでにやってきたこと。...> 新しいアイテムを追加> C++ クラスを実行しようとしましたが、「プロジェクトに 1 つ以上のファイルを追加できませんでした」というエラーで失敗しました。それらは、他のプロジェクト ファイルがあったフォルダーにありましたが、プロジェクトには含まれていませんでした。私がやりたいことは、テキスト編集のテキストを C++ 関数またはその他の可能な方法で変更するような単純なことです。
//Test.qml (main.qml)
import QtQuick 2.1
import QtQuick.Window 2.0
Rectangle {
id: rootRect
width: Screen.width/2
height: Screen.height/2
color: "gray"
Button{}
Rectangle{
id: textField
width: 120
height: 40
color: "white"
x:274; y: 61
border.color: "blue"
border.width: 4
radius: 2
}
TextEdit {
id: display
x: 274
y: 61
width: 80
height: 20
text: qsTr("Text Edit")
font.pixelSize: 22
color: "black"
anchors.centerIn: textField
}
Rectangle{
id: inputField
width: textField.width
height: textField.height
border.color: "green"
border.width: 3
color: "white"
x: 140; y: 61
}
TextEdit{
id: input
color: "red"
font.pixelSize: 30
anchors.centerIn: inputField
text: "Some Text"
}
}
//Button.cpl
import QtQuick 2.0
import QtQuick.Window 2.0
Item {
property string defaultText: "New Text"
Rectangle{
id: button
width: rootRect.width/6
height: rootRect.height/8
color: "black"
x: 200; y: 200
radius: 10
}
MouseArea{
id: buttonClickArea
width: 0
anchors.rightMargin: 0
anchors.bottomMargin: 0
anchors.fill: button
onClicked: {
display.text = defaultText
}
}
}
これおよび/または返信をお読みいただきありがとうございます。