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
[values]
1=8.56
2=10
[def]
def=1
To copy to clipboard, switch view to plain text mode
to this:
[values]
1=8.56
2=10
3=10
[def]
def=1
[values]
1=8.56
2=10
3=10
[def]
def=1
To copy to clipboard, switch view to plain text mode
but instead, I'm getting this:
[values]
1=8.56
2=10
[def]
def=1
3=10
[values]
1=8.56
2=10
[def]
def=1
3=10
To copy to clipboard, switch view to plain text mode
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();
ui->comboBox->count();
To copy to clipboard, switch view to plain text mode
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();
write<<"\n"<<i<<"="<<ui->newCalNumberAdd->text();
To copy to clipboard, switch view to plain text mode
void wave::on_addboardButton_clicked()
{
QSettings settings
("/home/test/Documents/Wave/signalgenerator.ini",
QSettings::IniFormat);
settings.beginGroup("values");
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");
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();
}
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();
}
To copy to clipboard, switch view to plain text mode
Bookmarks