PDA

View Full Version : [solved]Help!how to use QSettings save and read settings of QList<QTime>



75543255
2nd September 2009, 12:20
I want to save the QList<QTime> before quit the App add read it when the App run.


QList<QTime> timeList;
//save settings
settings.setValue("timeList",timeList);//Is this right?
//read settings
timeList=settings.value("timeList").toList();//It does work
//how can I do?


who can help me?
thank you!!

wysota
2nd September 2009, 12:26
QVariantList timeList;
timeList << QTime(...) << QTime(...);
settings.setValue("timeList", timeList);

QVariantList reading = settings.value("timeList").toList();
QList<QTime> times;
foreach(QVariant v, reading){
times << v.toTime();
}

75543255
2nd September 2009, 14:36
QVariantList timeList;
timeList << QTime(...) << QTime(...);
settings.setValue("timeList", timeList);

QVariantList reading = settings.value("timeList").toList();
QList<QTime> times;
foreach(QVariant v, reading){
times << v.toTime();
}
the code in second line can replaced by this:


//timeList << QTime(...) << QTime(...);
//QList<QTime> times;
//QVariantList timeList;
foreach(QTime t,times)timeList<<t;

My problem is solved.
Thank you very much.