PDA

View Full Version : reading QTextEdit from file



incapacitant
29th March 2006, 22:01
to write :


QFile file( s_filename );
if (file.open(QIODevice::WriteOnly))
{
QTextStream os(&file);
os << qMessage->toPlainText() << endl;
}


to read ?


qMessage << is; // 226


compiler says :
226 C:\Qt\test\sms\menu.cpp no match for 'operator<<' in '((ApplicationWindow*)this)->ApplicationWindow::qMessage << is'
note C:\Qt\4.1.1\src\corelib\tools\qchar.h:291 candidates are: QDataStream& operator<<(QDataStream&, const QChar&) etc...

How can I read in one step as I wrote to the file ?

NB idem if I use to QString as for >>

fullmetalcoder
29th March 2006, 22:15
qMessage.setPlainText( is.readAll() )

does that fit?

incapacitant
29th March 2006, 22:22
qMessage.setPlainText( is.readAll() );


compiler says
226 C:\Qt\test\sms\menu.cpp `setPlainText' has not been declared

even with include <QTextEdit> !

fullmetalcoder
29th March 2006, 22:45
looks like your textedit is a pointer while your previous code assumed it was not ( << operator doesn't work with pointers...)

try out "->" operator instead of "."