PDA

View Full Version : QColor vector in QSettings



Mint87
24th January 2013, 12:22
Hi everyone!

I want to save std::vector<QColor> ColorVector in QSettings. Tried a simple way:



QSettings settings;
settings.beginGroup("ColorConfigurationWidget");
settings.setValue("currentColorVector", ColorVector);
settings.endGroup();


But QSettings doesn't work with vectors, I guess.. The size of ColorVector is not fixed.
Does anyone know how to handle this problem?

Thank you!

Santosh Reddy
24th January 2013, 13:59
You should user Array not Group, see example


std::vector<QColor> ColorVector;
QSettings settings;

settings.beginWriteArray("ColorVector");
for(unsigned int i = 0; i < ColorVector.size(); i++)
{
settings.setArrayIndex(i);
settings.setValue("QColor", ColorVector.at(i));
}
settings.endArray();
settings.sync();

Mint87
24th January 2013, 14:09
Thanks a lot, Santosh!

wysota
25th January 2013, 15:02
Since QColor can fit into QVariant, you should (not sure, didn't test) be able to just use QVariantList for your color settings and save the list directly:


QSettings settings;
QVariantList colorList = myColorList();
settings.setValue("currentColorVector", colorList);