[Qt-interest] QBitArray and QSettings

Christian Ehrlicher Ch.Ehrlicher at gmx.de
Sat Aug 22 19:30:59 CEST 2009


Bob Hood schrieb:
> I'm not seeing a direct (obvious) way to store a QBitArray into a
> QSettings object in the same way I can with other types, so I wrote a
> pair of methods to convert to/from QString:
> 
>     QString MainWindow::bit_array_to_string(const QBitArray& array)
>     {
>         QString str;
>         for(int i = 0;i < array.size();i++)
>             str += (array[i] ? "1" : "0");
> 
>         return str;
>     }
> 
>     QBitArray MainWindow::string_to_bit_array(const QString& string)
>     {
>         QBitArray array;
>         array.resize(string.size());
> 
>         for(int i = 0;i < string.size();i++)
>             array[i] = (string[i] == '1');
> 
>         return array;
>     }
> 
> Must a QBitArray be converted to some other type before it can be stored
> and retrieved via a QSettings object, or did I just miss a
> less-than-obvious interface?
> 
QSettings takes an QVariant and QVariant has a ctor which takes a
QBitArray. So I would think that QSettings should be able to handle a
QBitArray.

Christian



More information about the Qt-interest-old mailing list