Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Brainstorm
  4. Read line and store info?

Read line and store info?

Scheduled Pinned Locked Moved Solved Brainstorm
4 Posts 3 Posters 1.0k 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.
  • D Offline
    D Offline
    davethedave
    wrote on last edited by
    #1

    Hello, so I'm fiddling around with qfile and looked at some tutorials, but I can't see how I can read the file line by line to for example
    store line 1 in username
    and line 2 as password.

    Currently doing this:
    QTextStream out(&file);
    out << username << endl;
    out << password << endl;

    It outputs the details in the format:
    test
    test

    I want to now store test in username and the other test in password, not sure if getline is what im looking for.

    1 Reply Last reply
    0
    • D Offline
      D Offline
      davethedave
      wrote on last edited by davethedave
      #2

      I tried doing something like
      QString line[2] = out.readLine();
      ui->lineusername->text() = line[0];
      ui->linepassword->text() = line[1];

      an array cannot be initialized with a parenthesized initializer

      JonBJ 1 Reply Last reply
      0
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by VRonin
        #3
        out.device()->seek(0); // move back to the start of the file
        ui->lineusername->setText(out.readLine());
        ui->linepassword->setText(out.readLine());
        

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        1 Reply Last reply
        2
        • D davethedave

          I tried doing something like
          QString line[2] = out.readLine();
          ui->lineusername->text() = line[0];
          ui->linepassword->text() = line[1];

          an array cannot be initialized with a parenthesized initializer

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #4

          @davethedave
          In addition to what @VRonin has shown, if your lineusername/linepassword are, say, QLineEdits, you cannot assign via text() = ... as you tried in yours, you'll want to use setText(). [EDIT As @VRonin 's example now shows.]

          1 Reply Last reply
          1

          • Login

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