![]() |
QAbstractListModel Help please!
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? |
Re: QAbstractListModel Help please!
Quote:
Quote:
in the class declaration in model.h Quote:
Code:
: m_type(type), m_size(size) gets initilized with the constructor parameters type and size. Quote:
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. |
Re: QAbstractListModel Help please!
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) 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? |
Re: QAbstractListModel Help please!
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) 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. |
Re: QAbstractListModel Help please!
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!!!! |
Re: QAbstractListModel Help please!
Quote:
Quote:
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. |
Re: QAbstractListModel Help please!
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. :) |
Re: QAbstractListModel Help please!
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! |
All times are GMT. The time now is 09:17. |
vBulletin® Version 3.8.8