[Qt-interest] Data Storage for QT Application

Andre Somers andre at familiesomers.nl
Tue Feb 9 17:03:21 CET 2010


Sean Harmer wrote:
> On Tuesday 09 February 2010 15:41:52 Oliver.Knoll at comit.ch wrote:
>   
>> Neville Dastur wrote on Tuesday, February 09, 2010 4:27 PM:
>>     
>>>>> ...
>>>>> my data is Country/Capital pair and number of entries can go upto
>>>>> ...
>>>>> Now with QSetting it always overwrite the key Country/Name  with
>>>>> ...
>>>>>           
>>> I'm sorry but all this is a bit silly (not meant as a flame etc). SQL
>>> seems like the man for the job.
>>>       
>> And if not SQL, why not writing into the good old QFile with Qt
>>  serialisation (http://doc.trolltech.com/4.6/qdatastream.html) instead of
>>  mis-using QSettings (yes, *settings*, which are meant to store application
>>  *settings* instead of data ;)?
>>
>> You can already write/read quite a lot of datatypes with a simple <<
>>  (respective >>) "out of the box":
>>  http://doc.trolltech.com/4.6/datastreamformat.html - including a QMap
>>  where you could store all your Country/Capital values.
>>
>> Cheers, Oliver
>>
>>     
>
> I agree. This is an abuse of QSettings but the OP seems to be unwilling to 
> learn the xml streamer classes or to use QFile, QTextStream and have a simple 
> csv type file.
>   
I agree as well, though the XML stream classes are not available in Qt 3 
which seems to be what the OP is using. Still, I'd say given the 
problem, I'd just go for either a simple CSV file or even streaming a 
QMap<QString, QString> containing the country->capital mapping directly 
to and from a file using QDataStream, depending on if you like to be 
able to edit the file manually. It's just a few lines of code in either 
case, though the QDataStream is the simplest I can think of as Qt does 
all the real work for you.

André




More information about the Qt-interest-old mailing list