Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QJson and QProperty #5

Open
Moth13 opened this issue Nov 23, 2012 · 2 comments
Open

QJson and QProperty #5

Moth13 opened this issue Nov 23, 2012 · 2 comments
Assignees
Labels

Comments

@Moth13
Copy link

Moth13 commented Nov 23, 2012

Hi Flavio,

Thanks for your genius lib, great job, very powerful.

I'm trying to use your QJson library to parse content from D3 Api. I use QProperty to initialize my objects.
It worked fine with standard value as int, QString, QDate, but how can use QList?

Example :

QJson from D3 Api :

{
"heroes" : [ {
"name" : "Toto",
"id" : 3
}, {
"name" : "Toto2",
"id" : 4
} ],
"lastHeroPlayed" : 3
}

My Class :

class D3_Heroe : public QObject
{
Q_Object
Q_PROPERTY(QString name READ getName WRITE setName)
Q_PROPERTY(int id READ getID WRITE setID)
...
}

class D3_Career : public QObject
{
Q_Object
Q_PROPERTY(QList<D3_Heroe> hereos READ getHeroes WRITE setHeroes)
Q_PROPERTY(QString lastHeroPlayed READ getlastHeroPlayed WRITE setlastHeroPlayed)
...
}

Using your QJson::QObjectHelper :

// _pReply is a QNetworkReply coming from D3_API
QVariant res = parser.parse( _pReply->readAll(), &bOk );
D3_Career pCareer = new D3_Career();
QJson::QObjectHelper::qvariant2qobject( res.toMap(), pCareer );

Any ideas?

Regards,
Jérémie

@Moth13
Copy link
Author

Moth13 commented Nov 26, 2012

Hi again,
I resolve my issue by using QVariant instead of QList<D3_Heroe>. So it use your QVariant::Type test in qvariant2qobject correctly.
And in D3_Career, in WRITE function, I parse this QVariant, still using qvariant2qobject.

By curiosity, why qvariant2qobject function don't handle QVariant::UserType?

Regards,
Jérémie

@flavio
Copy link
Owner

flavio commented Nov 28, 2012

By curiosity, why qvariant2qobject function don't handle QVariant::UserType?

Good catch, I'll take care of that with the next release.

@ghost ghost assigned flavio Nov 28, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants