kconfiggroup and unhandled types

Thomas Braxton kde.braxton at gmail.com
Mon Oct 29 05:24:10 GMT 2007


On 10/29/07, Aaron J. Seigo <aseigo at kde.org> wrote:
>
> On Sunday 28 October 2007, Thomas Braxton wrote:
> > did you also get QSizeF and QPointF? it seems those got lost as well :(
>
> heh.. you commited QPointF just before i did (i noticed it was missing
> only
> afterwords) ..
>
> on that note... for people who have custom data types and wish to store
> them
> in a kconfig, do they have to pre-serialize into a QByteArray and the
> deserialize on their own? (idle curiosity speaks =)


pretty much. the easiest way would be to write custom versions of
readEntry/writeEntry that take care of that for them, then they can just use
it like any other type.
something like...

template<>
QPointF KConfigGroup::readEntry(const QByteArray& key, const QPointF&
defaultValue) const
{
    const QByteArray data = readEntry(key, QByteArray());

    if (data.isNull())
        return defaultValue;

    if (data.isEmpty())
        return QPointF();

    const QList<QByteArray> list = data.split(',');
    return QPointF(list.at(0).toDouble(), list.at(1).toDouble());
}

template<>
void KConfigGroup::writeEntry(const QByteArray& key, const QPointF& value,
KConfigBase::WriteConfigFlags flags)
{
    QByteArray data="";

    if (!value.isNull())
        data += QByteArray::number(value.x()) + ',' + QByteArray::number(
value.y());
   writeEntry(key, data, flags);
}

one of these days I need to finish the API docs ;)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20071029/78c7f241/attachment.htm>


More information about the kde-core-devel mailing list