PDA

View Full Version : how to get a string value



jerkymotion
10th March 2011, 18:37
I want to get the string value from the TextEdit(GUI Widget) . let's say for example display the text of TextEdit1 to TextEdit2 after clicking the button...how is it possible please explain!!!

SixDegrees
10th March 2011, 18:40
Look at the documentation for QTextEdit; pay particular attention to those functions which take/return a QString.

squidge
10th March 2011, 18:58
Indeed, instead of feeding you, we prefer to teach you how to fish.

The Qt documentation is an excellent resource. Please read it before posting. It becomes obvious then how to perform the action you require.

If you still can't work it out then ask, after explaining what you have tried already.

jerkymotion
10th March 2011, 19:02
I have a question to ask if u don't mind..??
what is a value returned by this
ui->lineEdit->text(); Does it return a string type or something else ...
please help me because I am reallly getting confused!!!!!!!!

schnitzel
10th March 2011, 19:07
why the confusion?
Please take a look at the documentation of QLineEdit::text - http://doc.qt.nokia.com/latest/qlineedit.html#text-prop
It contains information about a 'setter' and a 'getter' and tells you exactly what the types are.

SixDegrees
10th March 2011, 19:10
I have a question to ask if u don't mind..??
what is a value returned by this
ui->lineEdit->text(); Does it return a string type or something else ...
please help me because I am reallly getting confused!!!!!!!!

Read the documentation; the return type of every function is documented.

Also, you started out talking about QTextEdit; now, you're referring to QLineEdit, an entirely different class. This isn't helpful.

jerkymotion
10th March 2011, 20:00
since for a line edit I wanted to copy the string value of line edit 1 to line edit 2 after pressing the button .....here's my code to do so but i couldn't success ....please help me ....
what's the matter ...

QString str;
str=ui->lineEdit->text();
ui->lineEdit_2->text()=str;

schnitzel
10th March 2011, 20:23
since for a line edit I wanted to copy the string value of line edit 1 to line edit 2 after pressing the button .....here's my code to do so but i couldn't success ....please help me ....
what's the matter ...

QString str;
str=ui->lineEdit->text();
ui->lineEdit_2->text()=str;

you got the 'getter' to 'get' the text, now you need to use the 'setter' to 'set' the text. I refuse to write this part for you. I can only yet again refer you to READ the documentation:
http://doc.qt.nokia.com/latest/qlineedit.html#text-prop
carefully study the 'access functions'

One more thing: if you are struggling to understand the difference between arguments of a function and the return value of a function, then I would suggest that you spend some time on google.

stampede
10th March 2011, 22:50
QString str;
str=ui->lineEdit->text();
ui->lineEdit_2->text()=str;
After looking at this code, I think it's not the best idea for you to start programming with Qt, because it requires some C++ knowledge. Without it, you won't be able to accomplish even such simple task ( displaying the string in text edit ).
I suggest reading a good C++ book ( for example this one (http://www.mindview.net/Books/TICPP/ThinkingInCPP2e.html) ) before starting with Qt.

Archa4
11th March 2011, 08:14
since for a line edit I wanted to copy the string value of line edit 1 to line edit 2 after pressing the button .....here's my code to do so but i couldn't success ....please help me ....
what's the matter ...

QString str;
str=ui->lineEdit->text();
ui->lineEdit_2->text()=str;

U can get the string using the:

QString str;
str = ui->lineEdit->text();

But to set this string to another lineEdit u have to do this:

ui->lineEdit2->setText(str);