Results 1 to 6 of 6

Thread: Reading text from a PlainTextEdit

  1. #1
    Join Date
    Mar 2011
    Posts
    3
    Thanks
    1

    Default Reading text from a PlainTextEdit

    Hello,

    This I'm sure is an immensely stupid question, however it's so simple that I can't find the answer to it by searching anywhere. I want to take the information from a PlainTextEdit, put it into a variable and use it elsewhere (for example to populate another box later on). I have the following, where LatEdit and EastingText are both PlainTextEdit's, but get the error 'LatEdit was not declared in this scope'. If I change it to 'num1 = "TEST";' then it will work, so I'm assuming it's me reading in the text incorrectly from the LatEdit control.
    Qt Code:
    1. void MainWindow::on_pushButton_clicked()
    2. {
    3. QString num1;
    4. num1 = LatEdit->Plain;
    5. ui->EastingText->setPlainText(num1);
    6. }
    To copy to clipboard, switch view to plain text mode 

    Can anyone help me?

    Thanks

  2. #2
    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: Reading text from a PlainTextEdit

    are you forgetting to put 'ui->' in front of LatEdit?

  3. #3
    Join Date
    Oct 2010
    Location
    Belarus
    Posts
    71
    Thanks
    1
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Windows Maemo/MeeGo

    Default Re: Reading text from a PlainTextEdit

    QPlainTextEdit::toPlainText () ?

    Qt Code:
    1. num1 = ui->LatEdit->toPlainText ();
    To copy to clipboard, switch view to plain text mode 
    Try read Qt documentation before ask stupid question.

  4. The following user says thank you to unit for this useful post:

    Bertie (8th March 2011)

  5. #4
    Join Date
    Mar 2011
    Posts
    3
    Thanks
    1

    Default Re: Reading text from a PlainTextEdit

    Thank you, that worked! Didn't realise I needed toPlainText. More stupid questions to follow I expect...


    Added after 31 minutes:


    I'm not sure if I need to start a new thread, but I don't want to clog the board so I'll put it here. Could anyone tell me how I'd get mathematical functions into my code, such as Sine / Cosine etc.? Is there a math library I have to include?

    Thanks again
    Last edited by Bertie; 8th March 2011 at 22:05.

  6. #5
    Join Date
    Mar 2011
    Location
    Denmark
    Posts
    74
    Thanks
    7
    Thanked 10 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Reading text from a PlainTextEdit

    you need to include <QtCore> then you have access to qCos,qSin etc

    http://doc.qt.nokia.com/latest/qtcor...h.html#details

  7. #6
    Join Date
    Mar 2011
    Posts
    3
    Thanks
    1

    Default Re: Reading text from a PlainTextEdit

    Hello,

    I put
    Qt Code:
    1. #include <qtcore/qmath.h>
    To copy to clipboard, switch view to plain text mode 
    at the top of the main.cpp and mainwindow.cpp units, however when using qSqrt it said 'qSqrt was not declared in this scope'. I can however use
    Qt Code:
    1. #include "math.h"
    To copy to clipboard, switch view to plain text mode 
    with the sqrt command and that's fine. Any ideas why the qmath unit doesn't work?

Similar Threads

  1. Block the plainTextEdit
    By NewLegend in forum Newbie
    Replies: 6
    Last Post: 16th September 2010, 14:56
  2. How to set the Text Cursor in a PlainTextEdit box?
    By Mia S. in forum Qt Programming
    Replies: 2
    Last Post: 27th February 2010, 16:30
  3. Replies: 2
    Last Post: 13th February 2010, 18:33
  4. Access violation when reading big text files
    By robertson1 in forum General Programming
    Replies: 0
    Last Post: 18th September 2008, 06:59
  5. problem with reading text files
    By Axsis in forum Newbie
    Replies: 1
    Last Post: 25th April 2008, 12:29

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.