[solved] qtextstream
-
@
QFile file("C:/HeilfeFuerVieleWoerterZuErinnern/listaparole.txt");
if(file.open(QIODevice::Append | QIODevice::WriteOnly | QIODevice::Text))
{
QTextStream streami(&file);
QString tt = streami.readAll();
if(!(tt.contains(wort) && tt.contains(parola)))
{
streami.flush();
streami.seek(0);
streami << tipo << endl << wort << endl << beispiel << endl << parola << endl << esempio << endl << importanza << endl << "ENDB" << endl << endl;
}
}
file.close();
@why endl does not function?
-
Because you open your file WriteOnly and then try to read from it. You have to open it ReadWrite.
In addition, if you open your file with Append you cursor is at the end of the file when trying to readAll(). Thus the returned string will always be empty. Either you do not open your file with Append or you will have to add a streami.seek(0) before readAll().
-
Append places the cursor at the end of the stream, readAll() will always return an empty string (because there is nothing to read after the end of the stream). You will have to remove the Append flag or position your cursor at the beginning of the file using seek(0) before reading the contents.