Reply
Thread Tools
Posts: 642 | Thanked: 486 times | Joined on Aug 2008
#1
Hi guys,

Currently in the mix of developing a new app for the Nokia N9 (and N900) I would like to tap into the vast array of developers here to provide me with some pointers on the following points:


1) as part of my application I need to interact with a web service, my options are to use QDomDocument or QJSON.

2) How do I use QJSON? I come from a Java background so I'm not sure how I would need to include it into my application? I know with Java I just drop the jar file and add it to the class path and thats it? Do I need a .so file I can drop into my QML app? If so how would I add this to the classpath?

3) I'm also trying to create a QAbstractListModel for my QML app to use to increase performance and also to follow the MVC design pattern, however I am having trouble understanding the following classes:


http://doc.qt.nokia.com/4.7-snapshot...itemmodel.html

specifically the model.cpp file.

Is the very first method a constructor? And what it m_type/m_size? If it is a constructor it does look very strange? And how come there are two thing inside the same file? Animal and AnimalModel? Are there two classes in the same file?
 
nicolai's Avatar
Posts: 1,637 | Thanked: 4,424 times | Joined on Apr 2009 @ Germany
#2
Originally Posted by rash.m2k View Post
3) I'm also trying to create a QAbstractListModel for my QML app to use to increase performance and also to follow the MVC design pattern, however I am having trouble understanding the following classes:


http://doc.qt.nokia.com/4.7-snapshot...itemmodel.html

specifically the model.cpp file.

Is the very first method a constructor?
Yes

Originally Posted by rash.m2k View Post
And what it m_type/m_size?
These are members of class Animal, as you can see
in the class declaration in model.h

Originally Posted by rash.m2k View Post
If it is a constructor it does look very strange?
No. This line
Code:
    : m_type(type), m_size(size)
is an initializer list. The members m_type and m_size
gets initilized with the constructor parameters type and size.

Originally Posted by rash.m2k View Post
And how come there are two thing inside the same file? Animal and AnimalModel? Are there two classes in the same file?
You can put any number of class declarations/definitions
in your c++ source files. And there is no constraint like in jave, where a source files must be named
after the public class they contain.
 
Posts: 642 | Thanked: 486 times | Joined on Aug 2008
#3
thanks nicolai, that cleared somethings up, I understand it a little better now, I have a few follow up questions:

Code:
 : m_type(type), m_size(size)
this appears to be calling the m_type method/constructor with the parameter 'type'. however should it not be:

QString m_type = new QString(type)

within the body of the constructor?

This syntax is very confusing.

Also any idea how I go about including libraries within my application? such as the QJSON library?
 
nicolai's Avatar
Posts: 1,637 | Thanked: 4,424 times | Joined on Apr 2009 @ Germany
#4
You can ommit initialize lists and just initialize your members like you would
do in java:

Code:
Animal::Animal(const QString &type, const QString &size)
 {
    m_type = type;
    m_size = size;
 }
The problem with this type of initialization is, the member attributes of class
Animal are already constructed with default values. For QString this may
not be important. But if your member attributes are complex types, this
default initialisation may be time/memory consuming.
After the default initialization your constructor assigns new values
(here: type and string) to your member attributes which makes the default
initialization unneeded.
With initialization lists you avoid the propable useless default initialization for member attributes.

Regarding qjson,

the common way is to define library and library path for 3dparty
libs in your .pro file. like

LIBS += -L/usr/local/lib -lmath

(http://developer.qt.nokia.com/doc/qt...ect-files.html)

(I must admit, I don't know how Nokia handles 3dparty libs if you
want to release your app in ovistore. There are some restriction and
you should stay with nokias official API). Do you need qjson or
is QScript (part of the official API) enough.
 
Posts: 642 | Thanked: 486 times | Joined on Aug 2008
#5
Ah so what you are saying is initializing member variables like the way it is done in java means we are initializing them twice - first they are initialized to the default values and then set to the values we are passing in? And thus this is a waste of resources? - This makes sense?


I think I'll probably stick to QDomDocument - and do some xpath like expressions with it. The licensing thing might be tricky - but the QJSON is open source and I'm not making any changes to it so I may be fine? Some research needed on that anyway.

Thank you for your help! Very very much appreciated!!!!
 
nicolai's Avatar
Posts: 1,637 | Thanked: 4,424 times | Joined on Apr 2009 @ Germany
#6
Originally Posted by rash.m2k View Post
Ah so what you are saying is initializing member variables like the way it is done in java means we are initializing them twice - first they are initialized to the default values and then set to the values we are passing in? And thus this is a waste of resources? - This makes sense?
Yes!

Originally Posted by rash.m2k View Post
I think I'll probably stick to QDomDocument - and do some xpath like expressions with it. The licensing thing might be tricky - but the QJSON is open source and I'm not making any changes to it so I may be fine? Some research needed on that anyway.

Thank you for your help! Very very much appreciated!!!!

It is not about licensing. I just don't know how to include 3dparty
libs (anything nokia does not provide in their N9 SDK) in
your application if you want to publish it at ovi.
 
marxian's Avatar
Posts: 2,448 | Thanked: 9,523 times | Joined on Aug 2010 @ Wigan, UK
#7
For JSON parsing I have used this: http://ereilin.tumblr.com/post/68577...r-class-for-qt

The author states that he does not care what you do with it.
__________________
'Men of high position are allowed, by a special act of grace, to accomodate their reasoning to the answer they need. Logic is only required in those of lesser rank.' - J K Galbraith

My website

GitHub
 
Posts: 642 | Thanked: 486 times | Joined on Aug 2008
#8
Thank you both! I've had a look at qjsonparser:

http://git.forwardbias.in/?p=qjsonparser.git

there are only three files and it's easy to just drop them into my application.

I'm making decent progress actually, I've created a QAbstractList to hold my data, even created a new QObject class to call from QML to actually use the web service and create URL's and process the responses.

If it was java it would be so much easier! But got to learn this stuff!
 
Reply


 
Forum Jump


All times are GMT. The time now is 14:52.