TTKMusicPlayer  3.7.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
parserrunnable.cpp
Go to the documentation of this file.
1 /* This file is part of qjson
2  *
3  * Copyright (C) 2009 Flavio Castelli <flavio@castelli.name>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License version 2.1, as published by the Free Software Foundation.
8  *
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with this library; see the file COPYING.LIB. If not, write to
17  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20 
21 #include "parserrunnable.h"
22 #include "parser.h"
23 
24 #include <QtCore/QDebug>
25 #include <QtCore/QVariant>
26 
27 using namespace QJson;
28 
32 class ParserRunnable::ParserRunnablePrivate : public TTKPrivate<ParserRunnable>
33 {
34  public:
35  QByteArray m_data;
36 };
37 
39  : QObject(parent),
40  QRunnable()
41 {
43  qRegisterMetaType<QVariant>("QVariant");
44 }
45 
46 void ParserRunnable::setData(const QByteArray &data)
47 {
49  d->m_data = data;
50 }
51 
53 {
55 
56  bool ok = false;
57  Parser parser;
58  QVariant result = parser.parse (d->m_data, &ok);
59  if (ok) {
60  TTK_INFO_STREAM("successfully converted json item to QVariant object");
61  Q_EMIT parsingFinished(result, true, QString());
62  } else {
63  const QString errorText = tr("An error occurred while parsing json: %1").arg(parser.errorString());
64  TTK_ERROR_STREAM(errorText);
65  Q_EMIT parsingFinished(QVariant(), false, errorText);
66  }
67 }
QString errorString() const
This method returns the error message.
Definition: parser.cpp:123
void setData(const QByteArray &data)
Convenience class for converting JSON data to QVariant objects using a dedicated thread.
void parsingFinished(const QVariant &json, bool ok, const QString &error_msg)
This signal is emitted when the parsing process has been completed.
#define TTK_INFO_STREAM(msg)
Definition: ttklogger.h:67
Namespace used by QJson.
Definition: parser.h:34
QVariant parse(QIODevice *io, bool *ok=0)
Read JSON string from the I/O Device and converts it to a QVariant object.
Definition: parser.cpp:69
Convenience class for converting JSON data to QVariant objects using a dedicated thread private...
ParserRunnable(QObject *parent=nullptr)
#define TTK_INIT_PRIVATE(Class)
Definition: ttkprivate.h:33
Main class used to convert JSON data to QVariant objects.
Definition: parser.h:40
The class of the ttk private base.
Definition: ttkprivate.h:48
#define TTK_ERROR_STREAM(msg)
Definition: ttklogger.h:69
#define TTK_D(Class)
Definition: ttkprivate.h:41