Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Multiple variables into file

Multiple variables into file

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 1.1k Views 1 Watching
  • 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.
  • T Offline
    T Offline
    Tyler1234
    wrote on last edited by
    #1

    I want to save 4 different variables into a file, but with this code it only saves the last variable
    how do I save all the variables into the file??

    @QString name, username, password, age;
    
    name=ui->NameEdit->text();
    
    name=ui->UserNameEdit->text();
    
    name=ui->PasswordEdit->text();
    
    name=ui->AgeEdit->text();
    
    QString pfile = "Profile.dat";
    
    QFile file(pfile);
    
    file.open(QIODevice::WriteOnly|QIODevice::Text);
    
    QTextStream out(&file);
    
    out<<name<<" "<<username<<" "<<password<<" "<<age<<endl;
    
    file.close();@
    
    1 Reply Last reply
    0
    • A Offline
      A Offline
      andreyc
      wrote on last edited by
      #2

      Are there any warnings in the code?

      You use the same variable for all assignments and getting only value of age.

      1 Reply Last reply
      0
      • T Offline
        T Offline
        Tyler1234
        wrote on last edited by
        #3

        no.

        I changed it to this and it does the same thing
        @ QString name;
        QString username;
        QString password;
        QString age;
        name=ui->NameEdit->text();
        name=ui->UserNameEdit->text();
        name=ui->PasswordEdit->text();
        name=ui->AgeEdit->text();

        QString pfile = "Profile.dat";
        QFile file&#40;pfile&#41;;
        file.open(QIODevice::WriteOnly|QIODevice::Text);
        QTextStream out(&file);
        out<<name<<" "<<username<<" "<<password<<" "<<age<<endl;
        file.close();@
        
        1 Reply Last reply
        0
        • A Offline
          A Offline
          andreyc
          wrote on last edited by
          #4

          And you still use the same variable name to store all values.

          1 Reply Last reply
          0
          • T Offline
            T Offline
            Tyler1234
            wrote on last edited by
            #5

            ohhhhhh is see thank you! lol

            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