diff options
author | Marco Trevisan (Treviño) <mail@3v1n0.net> | 2016-10-18 11:44:04 +0200 |
---|---|---|
committer | Marco Trevisan (Treviño) <mail@3v1n0.net> | 2016-10-18 11:44:04 +0200 |
commit | 1adf4a6c1c9a978d1853612bf994f622599ea29a (patch) | |
tree | 467e5092cb7df72624fff1005b11c46ca393ac96 /libqmenumodel/src/converter.cpp | |
parent | c998da02c995ae39d688b10f6993f840a6573c68 (diff) | |
download | qmenumodel-1adf4a6c1c9a978d1853612bf994f622599ea29a.tar.gz qmenumodel-1adf4a6c1c9a978d1853612bf994f622599ea29a.tar.bz2 qmenumodel-1adf4a6c1c9a978d1853612bf994f622599ea29a.zip |
Converter: move parseVariantString here from UnityMenuModel
Diffstat (limited to 'libqmenumodel/src/converter.cpp')
-rw-r--r-- | libqmenumodel/src/converter.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/libqmenumodel/src/converter.cpp b/libqmenumodel/src/converter.cpp index 021fc82..527ae85 100644 --- a/libqmenumodel/src/converter.cpp +++ b/libqmenumodel/src/converter.cpp @@ -24,6 +24,7 @@ extern "C" { #include "converter.h" #include <QDebug> +#include <QString> #include <QVariant> /*! \internal */ @@ -137,6 +138,29 @@ static GVariant* toGVariant(const QString &typeName, const QVariant &value) return NULL; } +QVariant Converter::toQVariantFromVariantString(const QString &variantString) +{ + GVariant *gvariant; + GError *error = NULL; + + if (variantString.isEmpty()) { + return QVariant(); + } + + gvariant = g_variant_parse (NULL, variantString.toUtf8().data(), NULL, NULL, &error); + + if (error) { + qWarning() << "Impossible to parse" << variantString << "as variant string:"<< error->message; + g_error_free (error); + return QVariant(); + } + + const QVariant& qvariant = Converter::toQVariant(gvariant); + g_variant_unref (gvariant); + + return qvariant; +} + GVariant* Converter::toGVariant(const QVariant &value) { GVariant *result = NULL; |