PDA

View Full Version : Strings from LineEdit to Integers



Misko
11th August 2007, 22:28
Hi,

i want to calculate numbers obtained from a QLineEdit.
So i've used a QTextStream to pass the string to an integer like this:
QTextStream ts(&str);
ts << lineEditValue->text();
ts >> strInteger;
lineEditResult->setText(strInteger);
So for now i'm just trying to get the string from lineEditValue into lineEditResult via a QTextStream (then i want to pass an integer from lineEditValue into lineEditResult).

Clue anyone?
Thx,
Misko

marcel
11th August 2007, 22:31
You have QString::toUInt() to retrieve the integer value. No need for a QTextStream.

Regards

Misko
12th August 2007, 08:56
Hi Marcel,
Thx again!
Here's why I asked for it:
QString strA = lineEditA->text();
QString strB = lineEditB->text();
bool ok;
float lengthA = strA.toFloat(&ok);
float lengthB = strB.toFloat(&ok);
c = sqrt(lengthA*lengthA + lengthB*lengthB);
QString strHypothenusa = QString("%1").arg(c);
lineEditHypothenusa->setText(strHypothenusa);

As you can figure, it asks for 2 floats taken from LineEdits, calculates the hypothenusa and puts the value into another LineEdit.
Of course, no error-checking has been done (like entering negative numbers, ...). But for now is sufficient!

Regards,
Misko

jpn
12th August 2007, 11:11
As you can figure, it asks for 2 floats taken from LineEdits, calculates the hypothenusa and puts the value into another LineEdit.
Of course, no error-checking has been done (like entering negative numbers, ...). But for now is sufficient!
QDoubleValidator, QDoubleSpinBox