antuniooh
antuniooh

Reputation: 107

How to convert the text of qml a textField to float and int

I tried to pass a value inserted in textField in a C++ float variable.

The following code is a representation of what I need.

TextField{id:textField1}
Button{onClicked:function.printFloat = textField1.text.toFloat}

but I received the following warning message:

qrc:/qml/window/WindowConfigTelemetry.qml:215: Error: Cannot assign QString to float

What is wrong in my code ?

Upvotes: 3

Views: 7259

Answers (1)

Amfasis
Amfasis

Reputation: 4198

It's a bit hard with some parts of your code missing, but you can use the Javascript function parseInt and parseFloat

console.log("integer: ", parseInt(textField1.text))
console.log("float: ", parseFloat(textField1.text))

See https://doc.qt.io/qt-5/qtqml-javascript-functionlist.html for more helpful functions

Upvotes: 4

Related Questions