[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 << tipo << endl << wort << endl << beispiel << endl << parola << endl << esempio << endl << importanza << endl << "ENDB" << endl << endl;

    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().

  • all right! QIOdevice::Append is null with streami.readAll(); and then streami.seek(0);

  • 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.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.