mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-10 08:04:25 +02:00
Add wrapper to handle JSON parsing w.r.t. Qt version
This commit is contained in:
@@ -54,8 +54,12 @@
|
|||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include <QTranslator>
|
#include <QTranslator>
|
||||||
|
|
||||||
|
// Qt version specific includes
|
||||||
#if QT_VERSION >= QT_VERSION_CHECK( 5, 0, 0 )
|
#if QT_VERSION >= QT_VERSION_CHECK( 5, 0, 0 )
|
||||||
#include <QUrlQuery>
|
#include <QUrlQuery>
|
||||||
|
#include <QJsonDocument>
|
||||||
|
#else
|
||||||
|
#include <qjson/parser.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
@@ -842,6 +846,21 @@ compareVersionStrings( const QString& first, const QString& second )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QVariant
|
||||||
|
parseJson( const QByteArray& jsonData, bool* ok )
|
||||||
|
{
|
||||||
|
#if QT_VERSION >= QT_VERSION_CHECK( 5, 0, 0 )
|
||||||
|
QJsonParseError error;
|
||||||
|
QJsonDocument doc = QJsonDocument::fromJson( jsonData, &error );
|
||||||
|
*ok = ( error.error == QJsonParseError::NoError );
|
||||||
|
return doc.toVariant();
|
||||||
|
#else
|
||||||
|
QJson::Parser p;
|
||||||
|
return p.parse( jsonData, ok );
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
urlAddQueryItem( QUrl& url, const QString& key, const QString& value )
|
urlAddQueryItem( QUrl& url, const QString& key, const QString& value )
|
||||||
{
|
{
|
||||||
|
@@ -207,6 +207,9 @@ namespace TomahawkUtils
|
|||||||
* Qt4 / Qt5 compatibility layer
|
* Qt4 / Qt5 compatibility layer
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* QJson */
|
||||||
|
DLLEXPORT QVariant parseJson( const QByteArray& jsonData, bool* ok = 0 );
|
||||||
|
|
||||||
/* QUrl */
|
/* QUrl */
|
||||||
DLLEXPORT void urlAddQueryItem( QUrl& url, const QString& key, const QString& value );
|
DLLEXPORT void urlAddQueryItem( QUrl& url, const QString& key, const QString& value );
|
||||||
DLLEXPORT QString urlQueryItemValue( const QUrl& url, const QString& key );
|
DLLEXPORT QString urlQueryItemValue( const QUrl& url, const QString& key );
|
||||||
|
Reference in New Issue
Block a user