duma
29th August 2011, 18:04
I am having problems saving a line to my .ini file but it is not being sve din the place I want it to. I am trying to change it from:
[values]
1=8.56
2=10
[def]
def=1
to this:
[values]
1=8.56
2=10
3=10
[def]
def=1
but instead, I'm getting this:
[values]
1=8.56
2=10
[def]
def=1
3=10
I want the line 3=10 to be placed under [values], not under [def]. What am I doing wrong?
The code I have is below. The code takes the count of values in my combo box :
ui->comboBox->count(); and increases it by 1 (called "i" in the code. Then takes in a value written in a lineEdit called "newCalNumberAdd" and writes the line to the .ini file:
write<<"\n"<<i<<"="<<ui->newCalNumberAdd->text();
void wave::on_addboardButton_clicked()
{
QSettings settings("/home/test/Documents/Wave/signalgenerator.ini", QSettings::IniFormat);
settings.beginGroup("values");
const QStringList childKeys = settings.childKeys();
QHash<QString, QString> values;
foreach (const QString &childKey, childKeys) {
values.insert(childKey, settings.value(childKey).toString());
if (childKey.toInt() == ui->comboBox->currentIndex()+1) {
ui->calnumber->setText(settings.value(childKey).toString());
QFile file("/home/test/Documents/Wave/signalgenerator.ini");
file.open(QIODevice::ReadWrite| QIODevice::Text);
QTextStream write(&file);
QString line = write.readLine();
while (!line.isNull()){
int i = ui->comboBox->count();
i += childKey.toInt();
write<<"\n"<<i<<"="<<ui->newCalNumberAdd->text();
ui->comboBox->addItem("Board"+QString::number(i));
break;
}
file.close();
}
}
settings.endGroup();
}
[values]
1=8.56
2=10
[def]
def=1
to this:
[values]
1=8.56
2=10
3=10
[def]
def=1
but instead, I'm getting this:
[values]
1=8.56
2=10
[def]
def=1
3=10
I want the line 3=10 to be placed under [values], not under [def]. What am I doing wrong?
The code I have is below. The code takes the count of values in my combo box :
ui->comboBox->count(); and increases it by 1 (called "i" in the code. Then takes in a value written in a lineEdit called "newCalNumberAdd" and writes the line to the .ini file:
write<<"\n"<<i<<"="<<ui->newCalNumberAdd->text();
void wave::on_addboardButton_clicked()
{
QSettings settings("/home/test/Documents/Wave/signalgenerator.ini", QSettings::IniFormat);
settings.beginGroup("values");
const QStringList childKeys = settings.childKeys();
QHash<QString, QString> values;
foreach (const QString &childKey, childKeys) {
values.insert(childKey, settings.value(childKey).toString());
if (childKey.toInt() == ui->comboBox->currentIndex()+1) {
ui->calnumber->setText(settings.value(childKey).toString());
QFile file("/home/test/Documents/Wave/signalgenerator.ini");
file.open(QIODevice::ReadWrite| QIODevice::Text);
QTextStream write(&file);
QString line = write.readLine();
while (!line.isNull()){
int i = ui->comboBox->count();
i += childKey.toInt();
write<<"\n"<<i<<"="<<ui->newCalNumberAdd->text();
ui->comboBox->addItem("Board"+QString::number(i));
break;
}
file.close();
}
}
settings.endGroup();
}