[英]QML adding two inputs and returning result
I have a QML file, by V-Play (aka Felgo):我有一个 QML 文件,由 V-Play(又名 Felgo)提供:
import VPlayApps 1.0
import QtQuick 2.0
App {
id: app
// You get free licenseKeys from https://v-play.net/licenseKey
// With a licenseKey you can:
// * Publish your games & apps for the app stores
// * Remove the V-Play Splash Screen or set a custom one (available with the Pro Licenses)
// * Add plugins to monetize, analyze & improve your apps (available with the Pro Licenses)
//licenseKey: "<generate one from https://v-play.net/licenseKey>"
NavigationStack {
Page {
title: qsTr("My page")
}
AppTextField {
id: appTextField
x: 0
y: 329
width: 256
height: 19
anchors.centerIn: parent
placeholderText: qsTr('Enter a Number')
}
AppTextField {
id: appTextField1
x: 0
y: 329
width: 256
height: 19
anchors.verticalCenterOffset: 50
anchors.centerIn: parent
placeholderText: qsTr('Enter a Number')
}
TextEdit {
id: text1
x: 0
y: 620
width: 24
height: 20
text: qsTr('A')
font.pixelSize: 30
anchors.horizontalCenter: appTextField1.horizontalCenter
}
AppButton {
id: button
x: 0
y: 575
width: 24
height: 20
text: qsTr("Click me please!")
anchors.horizontalCenter: appTextField1.horizontalCenter
enabled: true
onClicked: {
text1.text=qsTr('Sum: '+(appTextField.text+appTextField1.text))
}
}
}
}
Which as expected returns my desired window, but now i want it to:正如预期的那样返回我想要的窗口,但现在我希望它:
Add the two inputs up after click of a button单击按钮后将两个输入相加
And display it on the TextEdit
并将其显示在TextEdit
I did my code, but it didn't work,我做了我的代码,但它不起作用,
I know you can create functions, but i don't know how to do what i want.我知道你可以创建函数,但我不知道如何做我想做的。
I tried the code above as you see.如您所见,我尝试了上面的代码。
The input in your TextEdit
is considered as String. TextEdit
的输入被视为字符串。 You have to convert it into numbers:您必须将其转换为数字:
onClicked: {
const v1 = parseInt(appTextField.text)
const v2 = parseInt(appTextField1.text)
text1.text=qsTr('Sum: ' + ( v1 + v2))
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.