00001 /* This file is part of qjson 00002 * 00003 * Copyright (C) 2009 Flavio Castelli <flavio@castelli.name> 00004 * 00005 * This library is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU Lesser General Public 00007 * License version 2.1, as published by the Free Software Foundation. 00008 * 00009 * 00010 * This library is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * Lesser General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU Lesser General Public License 00016 * along with this library; see the file COPYING.LIB. If not, write to 00017 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00018 * Boston, MA 02110-1301, USA. 00019 */ 00020 00021 #include "parserrunnable.h" 00022 00023 #include "parser.h" 00024 00025 #include <QtCore/QDebug> 00026 #include <QtCore/QVariant> 00027 00028 using namespace QJson; 00029 00030 class QJson::ParserRunnable::Private 00031 { 00032 public: 00033 QByteArray m_data; 00034 }; 00035 00036 ParserRunnable::ParserRunnable(QObject* parent) 00037 : QObject(parent), 00038 QRunnable(), 00039 d(new Private) 00040 { 00041 qRegisterMetaType<QVariant>("QVariant"); 00042 } 00043 00044 ParserRunnable::~ParserRunnable() 00045 { 00046 delete d; 00047 } 00048 00049 void ParserRunnable::setData( const QByteArray& data ) { 00050 d->m_data = data; 00051 } 00052 00053 void ParserRunnable::run() 00054 { 00055 qDebug() << Q_FUNC_INFO; 00056 00057 bool ok; 00058 Parser parser; 00059 QVariant result = parser.parse (d->m_data, &ok); 00060 if (ok) { 00061 qDebug() << "successfully converted json item to QVariant object"; 00062 emit parsingFinished(result, true, QString()); 00063 } else { 00064 const QString errorText = tr("An error occurred while parsing json: %1").arg(parser.errorString()); 00065 qCritical() << errorText; 00066 emit parsingFinished(QVariant(), false, errorText); 00067 } 00068 }
|
hosts this site. |
Send comments to: QJson Developers |