Saving values from Qlineedit and qcombobox?
I have a GUI, which have several text fields and some combobox. I want to give user a privilege to save these fields as a file and next time when he opens , he should have the option to select that file and all the values he set last time should reflect in those textboxes and combobox? how to do it.
Thanks in advance
Re: Saving values from Qlineedit and qcombobox?
Take a look at QApplication::saveState, maybe it helps. If not you may manually save items and current indices to the .ini file that you can load next time the application starts.
Re: Saving values from Qlineedit and qcombobox?
Thanks mentalmushroom. I am building this application on linux. I am not sure of .ini files in linux. I will look in to Qapplication::saveState. In mean time can you tell how to proceed using .ini files.
Re: Saving values from Qlineedit and qcombobox?
Saying .ini file I meant just an initialization file. It may have any structure or extension suitable for you. The idea was just to store all the content and parameters when you close the app, and when you start it again, read all the content and parameters and fill your controls with the data loaded.
Re: Saving values from Qlineedit and qcombobox?
Thanks...QApplication doesn't help.. Now can you please help how to save in a file and how to read it later..Thanks
Re: Saving values from Qlineedit and qcombobox?
Example how to write data to the file:
Code:
QDataStream out
(&file
);
// we will serialize the data into the file out <<
QString("the answer is");
// serialize a string out << (qint32)42; // serialize an integer
Read data from the file:
Code:
QDataStream in
(&file
);
// read the data serialized from the file qint32 a;
in >> str >> a; // extract "the answer is" and 42
There is also QTextStream class that is more convenient for writing/reading text.
Re: Saving values from Qlineedit and qcombobox?
Re: Saving values from Qlineedit and qcombobox?
Use file handling technique to save the file.
Use getter method to get the text from the textedit i.e. getText(), and for combo box use getvalue() and save these value to temp and write it into the file through file handling.
I think you know file handling or you can search through the internet.
Re: Saving values from Qlineedit and qcombobox?
Hey thanks to both of you.
Re: Saving values from Qlineedit and qcombobox?
Hey need help. how to "save as" for saving the fields.