Hi.  This is my first post and I am terribly stuck.  This seems like a
bug to me but I am not sure.

I have extended QVariantMap and added some convenience functions
fromFile and toFile which invoke QJson.  These seem to work but when I
add my extended class (after calling fromFile) to a QList<Properties>
and then clear it I get an error "Invalid address specified to
RtlValidateHeap".

One thing to note is that I am using of pre-release of Qt v4.8.  While
the error could be there I would think things like QVariantMap and
QString should remain solid (but maybe I am assuming too much here).

I appreciate any help.

Thanks.

-=ben


Here is my code:

------------ header ------------
#ifndef_Properties_h_

#define _Properties_h_

#include <QVariantMap>

class Properties : public QVariantMap

{

public:

        Properties();

        virtual ~Properties();

        bool fromFile(const QString & file);

        bool toFile(const QString & file, bool overwriteExisting=false);

};

#endif

------------ source ------------
#include "Properties.h"

#include <QFile>
#include <QDebug>

#include "QJson/Parser" 
#include "QJson/Serializer"

Properties::Properties() : QVariantMap()
{

}

Properties::~Properties()
{

}

bool Properties::fromFile(const QString & file)
{
        if (!QFile::exists(file)) return false;

        QFile f(file);
        if( !f.open(QIODevice::ReadOnly) ) return false;

        QJson::Parser parser;
        bool ok;

        QVariantMap data = parser.parse(f.readAll(), &ok).toMap();
        if( !ok ) return false;

        *static_cast<QVariantMap*>(this) = data;

        qDebug() << "loaded file: " << file;
        qDebug() << *static_cast<QVariantMap*>(this);

        return true;
}

bool Properties::toFile(const QString & file, bool overwriteExisting)
{
        if( !overwriteExisting && QFile::exists(file) ) return false;

        QFile f(file);
        if( !f.open(QIODevice::WriteOnly|QIODevice::Truncate) ) return false;

        QJson::Serializer s;
        bool ok;
        s.serialize(*((QVariantMap*)this), &f, &ok);

        qDebug() << "saved file: " << file;

        return ok;
}


------------ test ------------

When I try this it gives that error in list.clear:

        Properties prop;
        prop.fromFile("test.json");
        QList<Properties> list;
        list.append(prop);
        list.clear(); <--- causes error

Yet this test works ok:

        Properties prop;
        prop.insert(tr("name1"), tr("value1"));
        prop.insert(tr("name2"), tr("value2"));
        QList<Properties> list;
        list.append(prop);
        list.clear();

------------ test.json ------------
{ "name1" : "value1", "name2" : "value2" }

 

------------------------------------------------------------------------------
BlackBerry&reg; DevCon Americas, Oct. 18-20, San Francisco, CA
Learn about the latest advances in developing for the 
BlackBerry&reg; mobile platform with sessions, labs & more.
See new tools and technologies. Register for BlackBerry&reg; DevCon today!
http://p.sf.net/sfu/rim-devcon-copy1 
_______________________________________________
QJson-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/qjson-devel

Reply via email to