7

如何TextInput在 qml 中将一个分配给一个 int?

int new_span_seconds

TextInput {
        id: editor
        width: 80
        height: 17
        color: "white"
        font.bold: true; font.pixelSize: 14
        text: "21"
        horizontalAlignment: TextInput.AlignHCenter

    }

    Keys.forwardTo: [ (returnKey), (editor)]

    Item {
        id: returnKey
        Keys.onReturnPressed: new_span_seconds = editor. <<< ?  >>>
        Keys.onEnterPressed:  new_span_seconds = editor. <<< ?  >>>
    }
4

2 回答 2

8

这只是一段 Javascript

Keys.onReturnPressed: new_span_seconds = parseInt(editor.text)
于 2011-07-03T11:02:36.977 回答
0

利用 的 jenky 部分js,它允许您通过“相乘”将字符串转换为整数。前任 let foo = "2"; let bar = foo * 1.

以下是应用于您提供的特定代码时的外观:

TextInput {
        id: editor
        width: 80
        height: 17
        color: "white"
        font.bold: true; font.pixelSize: 14
        text: "21"
        horizontalAlignment: TextInput.AlignHCenter

    }

    Keys.forwardTo: [ (returnKey), (editor)]

    Item {
        id: returnKey
        Keys.onReturnPressed: new_span_seconds = editor.text * 1
        Keys.onEnterPressed:  new_span_seconds = editor.text * 1
    }
}
于 2021-07-23T03:08:45.570 回答