Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. [solved] qtextstream
QtWS25 Last Chance

[solved] qtextstream

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 2 Posters 7.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    spode
    wrote on last edited by
    #1

    @
    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?

    1 Reply Last reply
    0
    • L Offline
      L Offline
      lgeyer
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • S Offline
        S Offline
        spode
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • L Offline
          L Offline
          lgeyer
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved