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
Regular Contributor
Posts: 70
Registered: ‎09-06-2012
My Device: Developer
My Carrier: Bell Mobility

QString and string in QML and C++

Can't find any info on how to resolve this issue.

 

In C++ I can define a QString and in QML I can define a string. And, I want to communicate between QML and C++ using javascript functions.

 

Why examples use hardcoded values I don't know. That is not the real world, values are read from files, databases and user input so that is how examples should be written. If they were I wouldn't be asking this question.

 

My communication (QML<-->c++) is not working and because I can't find any documentation that clearly says what the relationship is between a string and a QString, what includes or imports are required to use in appropriate, whether javascript recognizes a QString, string etc I don't know if incompatability is the issue.

 

I can define a "string" property but not a "QString" property for a QML control.

 

Can anyone clarify the relationship or point to documentation or to an example that shows an interchange of data between QML and C++ method with QString arguments/parameters.

Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: QString and string in QML and C++

There's a layer which translates "transparently" between QML strings and QStrings, so this should generally just work.

You probably should post some code snippets showing what you're trying to do... but if you think you can sort it out with some documentation, make sure you've read the "C++ and QML integration" section here https://developer.blackberry.com/cascades/documentation/dev/index.html

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Regular Contributor
Posts: 70
Registered: ‎09-06-2012
My Device: Developer
My Carrier: Bell Mobility

Re: QString and string in QML and C++

I've already read the integration document and based by objects on it.

 

No where have I found any statement that says QStrings are only used in C++ and sometimes but not always handles the communication between them and strings. When a lot of things aren't working one does need to check and get answers to potential problems and how strings are handled in any language especially C  are problematic for all programmers.

 

I managed to get a breakpoint on a method/function that showed the string was passsed to QString ok. Haven't done the reverse yet but not an issue yet.

 

So what is not working is methods are not recognized. No compile errors, no execution error messages, method is not entered, breakpoint is not reached.

 

Now, tried with two classes. Same issue one method is executed as expected, another is not. Does not matter whether Q_INVOKABLE is specified for either one that executes/doesn't execute. In other words method A executes always, method B  never does. 

 

I made Method B a WRITE for a Q_PROPERTY and it worked. Method A is a strait method call an it works.

 

So I don't have a clue why a method that looks and is defined like any other method is not invoked.

 

 

Developer
Posts: 1,650
Registered: ‎04-08-2010
My Device: Z10 (red Limited Edition), Q10, Z30
My Carrier: Telekom.de, O2, Vodafone

Re: QString and string in QML and C++

as Peter wrote: posting some code would help

 

I'm doing communication between C++ and QML in both directions and it works.

there are so many examples out there from Cascades site and you should also go through the examples from Cascades-Samples and Cascades-Community-Samples on github

 

this will cost some time - but it's worth

 

it's a new platform and it's a beta - and for this - from my POV - the documentation and samples together with all the help from this forum and on Twitter RIM does a good job to help devs to start with Cascades

 

 

-------------------------------------------------------------------------------
ekke (independent software architect, rosenheim, germany)

BlackBerry Elite Developer
BlackBerry Platinum Enterprise Partner
International Development Mobile Apps BlackBerry 10 Cascades
Cascades - Workshops / Trainings / Bootcamps

blog: http://ekkes-corner.org videos: http://www.youtube.com/user/ekkescorner http://vimeo.com/ekkescorner/videos
bb10-development: http://appbus.org Twitter: @ekkescorner
New Contributor
Posts: 8
Registered: ‎01-02-2013
My Device: playbook, bb10
My Carrier: starhub

Re: QString and string in QML and C++

hello.. did you solve the problem? I mean the qstring and string communication between c++and qml, I also encounter the problem, and i search find the Qstring has a toSTDstring()  function to do that.. but i did not success on that.. could u tell me how you solve that? thanks 

Developer
Posts: 1,650
Registered: ‎04-08-2010
My Device: Z10 (red Limited Edition), Q10, Z30
My Carrier: Telekom.de, O2, Vodafone

Re: QString and string in QML and C++

what exactly is your problem ?

without describing your usecase and some code it's difficult to guess

 

 

-------------------------------------------------------------------------------
ekke (independent software architect, rosenheim, germany)

BlackBerry Elite Developer
BlackBerry Platinum Enterprise Partner
International Development Mobile Apps BlackBerry 10 Cascades
Cascades - Workshops / Trainings / Bootcamps

blog: http://ekkes-corner.org videos: http://www.youtube.com/user/ekkescorner http://vimeo.com/ekkescorner/videos
bb10-development: http://appbus.org Twitter: @ekkescorner
New Contributor
Posts: 8
Registered: ‎01-02-2013
My Device: playbook, bb10
My Carrier: starhub

Re: QString and string in QML and C++

well, actually my problem is solved, previously I wanna assign some QString value achieved from database to one string property in qml, which this process seems got some error.. that's why I asked how to communication from Qstring from C++ with string from QML..

code may like :

in xxx.qml

 

property string id

......

ListView{

......

onTrigered{

var selectedItem = dataModel.data(indexPath);

id=selectedItem.customerID;
}// customerID is Qstring and id is string, so this could not work, and the problem is how make it work.

 

Developer
Posts: 84
Registered: ‎12-01-2012
My Device: 9790
My Carrier: Orange

Re: QString and string in QML and C++

You could try something like:

id=""+selectedItem.customerID;

if the customerID is not QString it will be casted to string. If it is QString it should be casted straight away.
Lublin BlackBerry Developer Group


---
If I helped you please mark my response as solution or "Like" it.