Good morning, I want to improve a GUI with QT c++ to read, edit and save info in a txt file. This is what I have:
- A txt file with some parameters written (like "A=1 B=5 ...")
And I have been able to do the following with my qt code in c++ :
2.1. I have created a GUI where those parameters (A, B, ...) will be shown in labels, and its values will be shown in lineEdits (1, 5, ...)
2.2. I can edit the lineEdits, but I am not sure how to save them
My question is:
How can I save the info? Should I make the code to save the changes everytime anything change? Or all together at the end? or...? I do not know enought to make this.
CODES
To show the values, I used this:
const auto &config = AgCommConfig::getInstance(); //here my config.cpp was getting the info of the txt file
ui->lineEdit->setText(QString("%1").arg(config.speedchange())); //here my lineEdit shows the info of this txt file
And to save the info back in the txt file, I was starting with this:
void MainWindow::on_lineEdit_editingFinished()
{
QString input = ui->lineEdit->text();
}
I have the variable now, but I do not know if the fuction is the correct one (I think yes), and I do not know how to continue to overwrite the info in the txt file
. . EDIT:
I suppose that the easiest way is to save (overwrite) all the data in 1 go as you said, and not continously.
I do not want to change the labels. Only the values, and update them in the txt file.
So mainly, I suppose that for each value, I should have 1 variable. And it will be udpated everytime with the fuction ''editingfinished''. When he click in a new ''save all'' button, the code should create a new txt file with the same name to overwrite the old one.
But the problem are the comments... I could maybe save them in a variable, but they will be hard to order them again.
Tell me please if there is any other easiest way in any point, or in total
Thanks in advance a lot!