[Qt-interest] Reading values from a QTextEdit
Colin S. Miller
no-spam-thank-you at csmiller.demon.co.uk
Mon Oct 12 12:34:23 CEST 2009
Sujan Dasmahapatra wrote:
> Dear Friends
> I want to read some values from a QTextEdit is there a way to read
> values can I treat QTextEdit just like a file ?
> My QTextEdit is a member of my dialog box. Now I want the user to enter
> values in the QTextEdit manually and then read these values.
> My set of values are like these.
>
> The first value = noOfPoints
> The 2nd value is the first point value and the 3rd value is the 2nd point.
> These values will be changed when user writes the first value as 10
> then he has to enter 10 point values followed by.
>
> If I have A Text Edit in my dialog box then how can I read values from
> the Text Edit once user presses 'ok' button in the dialog box !!!!
>
> 2 0.222 0.21212
Sujan,
the documentation for Qt is available on line at
http://doc.trolltech.com/
The normal way of reading data from a QTextEdit is
to call QTextEdit::toPlainText()
this returns a const QString representing the contents
of the QTextEdit without formatting.
You'd normally use the accessor functions in QString
to parse it. (QString::indexOf(....) will look for spaces or tabs, etc).
If you do want to access a QString as a file, then do
QString rwStr=QString(QString(myTextEdit->toPlainText());
QTextStream myStream(rwStr, QIODevice::ReadOnly);
The QTextStream can then be used with the standard file >> operator.
Ideally I'd pass the const QString directly to the QTextStream, but it doesn't
take a const QString, although the documentation for QTextIStream suggests that it
should.
HTH,
Colin S. Miller
More information about the Qt-interest-old
mailing list