Multiple variables into file
-
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();@
-
Are there any warnings in the code?
You use the same variable for all assignments and getting only value of age.
-
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(pfile); file.open(QIODevice::WriteOnly|QIODevice::Text); QTextStream out(&file); out<<name<<" "<<username<<" "<<password<<" "<<age<<endl; file.close();@
-
And you still use the same variable name to store all values.
-
ohhhhhh is see thank you! lol