PDA

View Full Version : Reading text from a PlainTextEdit



Bertie
8th March 2011, 21:11
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.


void MainWindow::on_pushButton_clicked()
{
QString num1;
num1 = LatEdit->Plain;
ui->EastingText->setPlainText(num1);
}


Can anyone help me?

Thanks

schnitzel
8th March 2011, 21:17
are you forgetting to put 'ui->' in front of LatEdit?

unit
8th March 2011, 21:20
QPlainTextEdit::toPlainText () ?


num1 = ui->LatEdit->toPlainText ();

Bertie
8th March 2011, 22:05
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

Berryblue031
9th March 2011, 09:28
you need to include <QtCore> then you have access to qCos,qSin etc

http://doc.qt.nokia.com/latest/qtcore-qmath-h.html#details

Bertie
9th March 2011, 14:24
Hello,

I put
#include <qtcore/qmath.h> 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
#include "math.h" with the sqrt command and that's fine. Any ideas why the qmath unit doesn't work?