Hi Matthew,
Mike is right, you assume here that QVariant constructor understands the
JSON syntaxe, which is not the case. For what you want to do, you have 2
solutions:
1- construct your QVariant in your code by hand, i.e. :
QVariantList l;
QVariantList v;
v.append(24.1107);
v.append(30.3990);
l.append(v);
etc..
2- Create a JSON string as you did, and convert it to QVariantMap using the
QtJsonParser (You need to pass your string as a QIODevice, so you need to
use a QBuffer)
Method 2 is easier for testing, but 1 would be faster and you will avoid
converting double to string for finally reparsnig them...
Fabien
On Tue, Nov 11, 2008 at 3:40 PM, Matthew Gates <matthewg42@...> wrote:
> Hi Fabien.
>
> I am looking at adding a slot to SkyImageMgr to load an image using
> parameter provided as parameters of the function (rather than from a json
> file).
>
> Would this approach be a good idea: create a QVariantMap from the
> parameters and call SkyImageTile::loadFromQVariantMap, then adding that tile
> using SkyImageMgr::insertSkyImage?
>
> I looked in loadFromQVariantMap to see what keys I need in the QVariantMap
> which is a parameter to that function. It seems straight forward, but I'm
> having trouble with the coordinates. it's probably something silly, but I am
> having real trouble working out how to create a QVariant which can
> successfully split into a list using QVariant::toList.
>
> When I do a test like this:
>
> QVariant v("[[[24.1107, 30.3990], [23.1405, 30.0970], [22.7842, 30.9333],
> [23.7618, 31.2379]]]");
>
> foreach(QVariant i, v.toList())
>
> {
>
> qDebug() << i;
>
> }
>
> ... I get no output at all. Do you know what I'm doing wrong?
>
> Matthew
>
> -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move Developer's
> challenge
> Build the coolest Linux based applications with Moblin SDK & win great
> prizes
> Grand prize is a trip for two to an Open Source event anywhere in the world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> _______________________________________________
> Stellarium-pubdevel mailing list
> Stellarium-pubdevel@...
> https://lists.sourceforge.net/lists/listinfo/stellarium-pubdevel
>
>
|