PDA

View Full Version : INI file gets over written in Qt



SiddhantR
10th October 2013, 13:16
I am creating a config file which stores username, password and role of certain user. I use the following code.


void MainWindow::OnAssignButtonClicked()
{
QSettings settings("/root/configFile.ini", QSettings::IniFormat);

QString userName = lineEditUsername.text();
QString password = lineEditPassword.text();
QString Role = comboBox.currentText();

QList<QString> listUsername;
QList<QString> listPassword;
QList<QString> listRole;

QVariantMap userPasswordMapping;
QVariantMap userRoleMapping;

listUsername << userName;
listPassWord << Password;
listRole << Role;

for(int i = 0; i < listUsername.size() ; i++)
{
QString user = listUsername.at(i);
QString pass = listPassword.at(i);
QString role = listRole.at(i);

userPasswordMapping[user] = pass;
userRoleMapping[user] = role;
}

// Store the mapping.
settings.setValue("Password", userPasswordMapping);
settings.setValue("Role",userRoleMapping);

}
The first time the value gets written correctly. However if I run the program again the value over writes the old values. Can some one please suggest me a solution here?
Thank You

wysota
10th October 2013, 13:24
You are calling setValue() so the value for that key is stored in the settings. Did you expect it to be different?

SiddhantR
10th October 2013, 13:40
Ok so what change should I do?

wysota
10th October 2013, 15:25
Ok so what change should I do?

I have no idea what you want to achieve.