Saving data from form to txt file
-
Hello,
I have a problem with saving data from lineEdit end etc. to txt File.@void MainWindow::on_pushButton_2_clicked()
{
QString fileName = QFileDialog::getSaveFileName(this, tr("Zapisz plik"), "",
tr("Plik tekstowy (.txt);;Plik C++ (.cpp *.h)"));if (fileName != "") { QFile file(fileName); if (!file.open(QFile::WriteOnly | QFile::Text)) { // error } else { QTextStream stream(&file); stream.setIntegerBase(10); stream << "Czas: " << timeEdit->time().toString() << "\n\n"; stream << "Data: " << dateEdit->date().toString() << "\n\n"; stream << "Miejsce: " << lineEdit->text() << "\n\n"; stream << "Temat: " << lineEdit_2->text() << "\n\n"; //stream << "Wiadomosc: " << textEdit-> << "\n\n"; stream.flush(); file.close(); } }
}@
Content of .txt file:
Czas:
Data: 0x4
Miejsce: 0x22fe48
Temat: 0x40bab2
Wiadomosc: 0x0
What is wrong ?
Greetings ! -
What happens when you use QFile::write() instead of a stream?
-
Error:
'Write' is not a member of 'QFile'
-
-
the code of your first post works fine for me.
Try adding the following line:
@
stream.setCodec("UTF-8");
@