Results 1 to 10 of 10

Thread: how to get a string value

  1. #1
    Join Date
    Mar 2011
    Posts
    35
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Windows

    Default how to get a string value

    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!!!

  2. #2
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: how to get a string value

    Look at the documentation for QTextEdit; pay particular attention to those functions which take/return a QString.

  3. #3
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how to get a string value

    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.

  4. #4
    Join Date
    Mar 2011
    Posts
    35
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how to get a string value

    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!!!!!!!!

  5. #5
    Join Date
    Oct 2009
    Posts
    364
    Thanks
    10
    Thanked 37 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: how to get a string value

    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.

  6. The following user says thank you to schnitzel for this useful post:

    jerkymotion (10th March 2011)

  7. #6
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: how to get a string value

    Quote Originally Posted by jerkymotion View Post
    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.

  8. The following user says thank you to SixDegrees for this useful post:

    jerkymotion (10th March 2011)

  9. #7
    Join Date
    Mar 2011
    Posts
    35
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how to get a string value

    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;

  10. #8
    Join Date
    Oct 2009
    Posts
    364
    Thanks
    10
    Thanked 37 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: how to get a string value

    Quote Originally Posted by jerkymotion View Post
    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.
    Last edited by schnitzel; 10th March 2011 at 20:50. Reason: clarify

  11. #9
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: how to get a string value

    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 ) before starting with Qt.

  12. #10
    Join Date
    Feb 2011
    Location
    Latvia
    Posts
    139
    Thanks
    24
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how to get a string value

    Quote Originally Posted by jerkymotion View Post
    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:
    Qt Code:
    1. QString str;
    2. str = ui->lineEdit->text();
    To copy to clipboard, switch view to plain text mode 

    But to set this string to another lineEdit u have to do this:
    Qt Code:
    1. ui->lineEdit2->setText(str);
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Agent String
    By mind_freak in forum Qt Programming
    Replies: 0
    Last Post: 6th April 2010, 12:26
  2. std:string how to change into system:string?
    By yunpeng880 in forum Qt Programming
    Replies: 1
    Last Post: 14th April 2009, 08:51
  3. Int to String - manipulating string
    By mickey in forum General Programming
    Replies: 6
    Last Post: 5th November 2007, 20:11
  4. string height
    By agaf in forum Qt Programming
    Replies: 1
    Last Post: 24th January 2007, 08:21
  5. String value
    By Gayathri in forum Newbie
    Replies: 2
    Last Post: 21st November 2006, 05:44

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.