Strings from LineEdit to Integers
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
Re: Strings from LineEdit to Integers
You have QString::toUInt()to retrieve the integer value. No need for a QTextStream.
Regards
Re: Strings from LineEdit to Integers
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
Re: Strings from LineEdit to Integers
Quote:
Originally Posted by
Misko
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