PDA

View Full Version : HOw to insert end of line while appending text in a file



deekayt
17th November 2006, 11:03
I am trying to put several lines in a file. But want to insert end of line after every message. I have tried endl and \n but it doesnot work

the code is as

void steg::imagefileopen()
{

QString datafilename=ui.datalineEdit->text();
QFileInfo info1(datafilename);

QFileDialog* fd = new QFileDialog( this);
fd->setFileMode( QFileDialog::AnyFile );

QString s = QFileDialog::getOpenFileName(this,"Choose a IMAGE file to open","image_bank","All Files (*.*)");

ui.imagelineEdit->insert(s);
QFileInfo info(s);
QString yes="THE DATA FILE CAN BE HIDDEN IN THE SELECTED IMAGE FILE ";
QString no ="THE DATA FILE IS TOO LARGE TO BE HIDDEN IN THE SELECTED "
"IMAGE FILE.CHOOSE LARGER IMAGE FILE ELSE CHOOSE SMALLER DATA FILE";
QString u = " The size of the image file is ";
QVariant v;
v.setValue(info.size());
QString t = v.toString();

QString y = " bytes";
u.append(t);
u.append(y);

if ( (0.10* info.size())>=(info1.size()))

u.append(yes);
else
u.append (no);

QFile size_file;
size_file.setFileName("sizeofdatafile.html");
size_file.open(QIODevice::Append);

QTextStream out(&size_file);
out << u;
size_file.close();
ui.textBrowser->clear();
QUrl myurl5;
myurl5=QUrl::fromLocalFile( "sizeofdatafile.html" ) ;
ui.textBrowser->setSource(myurl5);
}

am I missing something.
i know it should be easy
But somehow I am not ableto get it

munna
17th November 2006, 11:17
Adding '\n' works fine for me.

jacek
17th November 2006, 11:25
1. You are working with HTML, so \n is treated as a whitespace. Try adding <br/> tag.
2. Instead of creating a file on disk, you can store that message in a QString and then display it with ui.textBrowser->setHtml( message );