PDA

View Full Version : Problems saving a text file



aarelovich
20th September 2009, 22:11
Hi
I've written the following code


QString filename;
filename = QFileDialog::getSaveFileName(this,"Choose where to save","","*.jobs");
if (!filename.isEmpty()){
QFile file(filename);
if (file.open(QFile::WriteOnly)){
QTextStream out(&file);
out.setCodec("ISO 8859-1");
out << ui->teScript->toPlainText();
file.close();
}
else
QMessageBox::critical(this,"Error opening file",filename + "\ncould not be opened",QMessageBox::Ok);
}


Where teScript is a QTextEdit. So If I write something like (on the text edit, when executing the program):

Hello
my name is
John
Smith

and then I open the generated txt file (with notepad) i get every line concatenated with a strange square character in the middle.

So I was wondering how I could possibly fix this problem?
PS: The problem is in Windows.

SudaNix
20th September 2009, 23:46
change line 5 with this:


if (file.open(QFile::WriteOnly|QFile::Text))

Lykurg
21st September 2009, 08:26
just wondering: why are you using ISO 8859-1? If there is no real reason, I would change it to UTF-8. That could save you a lot of pain if you later need other languages used in your application...

aarelovich
27th September 2009, 15:39
Hi

I wasn't using the ISO standard. I added the line just to see if the problem was gone. As it turns out I didn't need to fix the problem.

But thanks for the answer.