PDA

View Full Version : How to query data by id in a text file



SamSong
26th May 2009, 07:48
Hi,all
I want to save the data in my MDI application, I want the data save as follows
subwindow1_id subwindow1data
subwindow2_id subwindow1data
.......
. so I can restore one subwindow data only by the subwindow_id
but I don't know how to do that with qt .
any idea ,thanks.

faldzip
26th May 2009, 08:08
The simplest way would be to use QSettings to store your data in the .ini file (using QSettings::IniFormat).

Example:


QSettings settings("mysavefile.ini", QSettings::IniFormat);
settings.setValue("subwindow1_id", QString("subwindow1data"));

the value is a QVariant so you can store almost anything.
reading:


QSettings settings("mysavefile.ini", QSettings::IniFormat);
QString str = settings.value("subwindow1_id").toString();

SamSong
26th May 2009, 08:18
but my data which is a QString in each mdisubwindowdata may be long ,is it suitable to use the QSettings

faldzip
26th May 2009, 10:34
I don't know if there is any limit, and don't know what "long" means exactly :] is it 100 characters? 100 lines? 100 pages? If there are a lot of data, maybe you should save them as XML file, maybe even in some more complicate structure or something? you can also store data in text file in the way you want and use the QString methods and/or QRegExps to read the data. But I would trye QSettings first, cause it looks like the simplest solution.

Lykurg
26th May 2009, 10:58
If you have more windows with the same parameters you also can use QSettings::beginGroup() instead of adding a index to the name. As a beginner I'd use QSetting at first. If you mere experienced you could use XML if it is really necessary.