Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
wantoun
Posts: 165
Registered: ‎10-04-2010
My Device: P'9982 & Z10
My Carrier: alfa Lebanon

Processing location info along with JSON Stored Info then Displaying on Interface

My app allows users to store locations (coordinates), I'm saving them as JSON.

The app then has to get the user's location, do some checks according to the stored locations then display the current location along with the stored ones.

 

I've implemented the storing and reading from JSON, I even think I got the location. My problem is how to get all these parts to "talk" with each other. I have the location functions in the app's main cpp and the JSON as another class module. How can I get all this information in the same place to check (I have to do this frequrntly) and then how can I get the location info to the QML (it's not the main QML page, it's a pushed page).

 

Everything is so dependant on classes, and C++ Classes are not really my thing. I might have to swtich to HTML5, it was much easier there although probably doesn't have that "native" feel.

 

Let me know if anything was not clear. Any help is really appreciated.

Wadi
Please use plain text.
BlackBerry Development Advisor
PBernhardt
Posts: 743
Registered: ‎12-16-2008
My Device: BlackBerry Z30
My Carrier: Bell

Re: Processing location info along with JSON Stored Info then Displaying on Interface

I think you may need to provide more details about the exact problem you are having, but you may find these links helpful:

 

http://developer.blackberry.com/cascades/documentation/dev/integrating_cpp_qml/index.html

http://developer.blackberry.com/cascades/documentation/dev/signals_slots/index.html

 

Paul Bernhardt
Application Development Consultant
BlackBerry
@PBernhardt

Did this answer your question? Please accept this post as the solution.
Found a bug? Report it to the Developer Issue Tracker
Please use plain text.
Developer
wantoun
Posts: 165
Registered: ‎10-04-2010
My Device: P'9982 & Z10
My Carrier: alfa Lebanon

Re: Processing location info along with JSON Stored Info then Displaying on Interface

Thanks for the reply!

 

I've looked into that documentation to get a variable from C++ to QML, it would be something like this:

QmlDocument *qml = QmlDocument::create("asset:///main.qml");
  
QDeclarativePropertyMap* propertyMap = new QDeclarativePropertyMap;
propertyMap->insert("name", QVariant(QString("Wes Barichak")));
propertyMap->insert("phone", QVariant(QString("519-555-0199")));
  
qml->setContextProperty("propertyMap", propertyMap);

 

But the problem is, the variable is not that simple as a string. The variable is the location that is being obtained periodicly inside a class function. How can I get to the main 'qml' variable if I'm inside a class function? I can't exactly pass it on.

 

Another issue is getting the location to yet another class which is the one that stores my information in a JSON. I basically used the one provided in the Bucket sample app.

Wadi
Please use plain text.
Developer
jalue
Posts: 196
Registered: ‎03-04-2013
My Device: BB Z10
My Carrier: Rogers

Re: Processing location info along with JSON Stored Info then Displaying on Interface

[ Edited ]

Well, you could create a 'get' member function in your JSON class that you created which would return an appropriate type (that contains your location coordinates) which you can use in your main...

Something like:

QList* myJSON::getLocationCoordinates() {

}

 

You don't necessarily have to use a QList (although it may work.. check https://developer.blackberry.com/cascades/reference/qlist.html to see how to populate a QList object)..  Maybe even a typedef struct {} locCoord;.  Fill that up in your 'get' member function and return it... It's all about getting your class properties out to the main through a return type function...

 

As for the QML stuff.. Create it all in your main.. Or even make a function that specifically creates the QML stuff.. You don't really need a specific QML file as the example you gave shows (you could but not really necessary)...

 

Check the Lightning Crossfade - Slider C++ example here:

https://developer.blackberry.com/cascades/sampleapps/

 

--Edit--

Well, if your QML control structures and layout doesn't change and only information does, then perhaps you should use a QML file..  And use the example idea you gave..

 

Also, for your location coordinates, you could check out QString::sprintf (or any other conversions you may need). My bad.. the API description states that you should really stay away from sprintf... Use QTextStream or arg() instead...

https://developer.blackberry.com/cascades/reference/qstring.html

 

As a side note, use whichever language you are comfortable with...

https://developer.blackberry.com/html5/

Please use plain text.