PDA

View Full Version : Retrieving the data from the screen in the GUI



Newbe
7th November 2012, 21:33
What is the best widget to use to retrieve doubles or integers from the user on the screen?
I am at a loss to figure out how to the get the data in order to manipulate it later in calculations.
For example:
int num1;
int num2;

int sum = num1 + num2

if I was in a console application I would use cin to get the data from the user. How do I do that in the GUI environment through a form?

Robbie
7th November 2012, 21:50
QSpinBox and QDoubleSpinBox

Newbe
7th November 2012, 21:59
Thanks but what if I want to use a simple box like a textEdit box for the user to type the integer or float into?

Urthas
8th November 2012, 07:12
Thanks but what if I want to use a simple box like a textEdit box for the user to type the integer or float into?

Then do that. See QString::toInt() and QString::toFloat().

Gokulnathvc
21st November 2012, 07:01
Use TextEdit and retrieve the values in QString and then convert those values to whatever format you are in need..

Santosh Reddy
21st November 2012, 08:46
You can use QLineEdit, and set input mask to allow only integers / float. See the documentation of QLineEdit::setInputMask()

anda_skoa
21st November 2012, 18:54
Thanks but what if I want to use a simple box like a textEdit box for the user to type the integer or float into?

QSpinBox and QDoubleSpinBox both allow direct user input additional to their "spin" input method.

Cheers,
_