PDA

View Full Version : Saving values from Qlineedit and qcombobox?



prabhudev
21st May 2012, 06:29
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

mentalmushroom
21st May 2012, 06:47
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.

prabhudev
21st May 2012, 09:40
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.

mentalmushroom
21st May 2012, 09:43
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.

prabhudev
21st May 2012, 09:50
Thanks...QApplication doesn't help.. Now can you please help how to save in a file and how to read it later..Thanks

mentalmushroom
21st May 2012, 09:54
Example how to write data to the file:


QFile file("file.dat");
file.open(QIODevice::WriteOnly);
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:


QFile file("file.dat");
file.open(QIODevice::ReadOnly);
QDataStream in(&file); // read the data serialized from the file
QString str;
qint32 a;
in >> str >> a; // extract "the answer is" and 42


There is also QTextStream class that is more convenient for writing/reading text.

prabhudev
21st May 2012, 10:01
I will try and post back

sonulohani
21st May 2012, 10:40
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.

prabhudev
21st May 2012, 13:16
Hey thanks to both of you.

prabhudev
23rd May 2012, 05:53
Hey need help. how to "save as" for saving the fields.