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
BlackBerry Development Advisor (Retired)
Posts: 499
Registered: ‎05-07-2012
My Device: developer

Re: Running C++ script using QML UI?

So is everything in this thread resolved?  If so, please mark solutions.

Otherwise, can you summarize what is still open.

 

Stuart

Developer
Posts: 262
Registered: ‎07-13-2012
My Device: PlayBook, DA B, DA C, LE Z10 #102, Q10, Z30

Re: Running C++ script using QML UI?

allsystemsgo hijacked the thread with his own issue that he solved himself but didn't answer anything about mine... so ignore his comments.

 

My last issue begin a few replies back beginning with: "Getting closer but still not working...."

---
Check out my BB10 Cascades Coding site: BBcascades.com & Cascades Blog: bbcascadescode.tumblr.com

My Built for BlackBerry app: The Dive Plan
Developer
Posts: 262
Registered: ‎07-13-2012
My Device: PlayBook, DA B, DA C, LE Z10 #102, Q10, Z30

Re: Running C++ script using QML UI?

The summary of the overall issue is I want the user to be able to input something (or two, three, four, ... somethings) have C++ crunch those numbers/values and spit out the "answer". The interface (QML) shows correctly and the C++ code runs fine in any generic C++ compiler... but how do I marry the two.  There is no signal/slots example that has this explained.

 

An even simpler case would be two inputs and a button and when the user puts a number in each box they press the button then a label below it shows the addition of the two inputs...

---
Check out my BB10 Cascades Coding site: BBcascades.com & Cascades Blog: bbcascadescode.tumblr.com

My Built for BlackBerry app: The Dive Plan
Developer
Posts: 224
Registered: ‎03-29-2012
My Device: 9900

Re: Running C++ script using QML UI?

[ Edited ]

hmm, so what errors do you currently have? It should be working from what we've looked at. But for your last comment, where two numbers are entered and a button click triggers the C code to do the math as you said, you're function must not be void, but be an integer taking the two parameters of the textArea inputs, then return an integer which is a sum of the total done in the C function. 

 

in the javascript of the qml button, put this:

 

var total= cs.clickButton()

 

now total is the sum of a+b. 

 

Follow that with with your signal to connect the buttonclick to the textboxes and then you're set.

Trusted Contributor
Posts: 140
Registered: ‎11-23-2010
My Device: Torch 9800

Re: Running C++ script using QML UI?

The BAD errors are normal so don't pay attention to those.

 

For the rest post your code so we can at least see what you mean.

Developer
Posts: 224
Registered: ‎03-29-2012
My Device: 9900

Re: Running C++ script using QML UI?

[ Edited ]

Okay so, for the scenario with two input areas and one button which sums them and displays the total in a label we begin with the two textAreas:

 

In Qml:

 

Container {

...

textArea {

id: textArea1

... //include an id, initial text value, etc.

}

 

textArea {

id: textArea2

...

}

 

Label {

id: totalLabel

...

}

 

Button {

signal sendTotal(int total)

id: addButton

.....

onClicked: {

var total = contextProperty.addNumbers(textArea1.text, textArea2.text);

totalLabel.text="" + total; //I cannot recall if text requires more than just a number

}

}

 

The cpp function has been called, go to the App.cpp file:

 

//remembering that the function must be in the App.hpp as well and be Q_INVOKABLE

 

App::addNumbers(int numberOne, int numberTwo) {

int total =  numberOne + numberTwo;

return total;

}

 

It returns to the button which then tells the label to change its text and we are done. Instead of using id's, a signal slot system could be used to connect the button total to the label's text but this was a bare bones example. I hope it works as a proof of concept and will continue to provide any help I can. 

 

 

Developer
Posts: 224
Registered: ‎03-29-2012
My Device: 9900

Re: Running C++ script using QML UI?

Did this help/work?

Trusted Contributor
Posts: 140
Registered: ‎11-23-2010
My Device: Torch 9800

Re: Running C++ script using QML UI?

let me look into it

Developer
Posts: 262
Registered: ‎07-13-2012
My Device: PlayBook, DA B, DA C, LE Z10 #102, Q10, Z30

Re: Running C++ script using QML UI?

Your adding example helped but was missing way too many pieces to work with so I went back to my original table example but applied what you did have in the adding example to move it along but sitll not working properly.  I'm out of ideas... attached is what I have. 

 

The way it sits I get an error of... Error: Invalid write to global property "read"

 

But if I add "char read" to inside of the parenthesis of int App::clickedButton(int in1, int in2) in app.cpp and Q_INVOKABLE int clickedButton(int in1, int in2); in app.hpp I get an error of...  Error: Insufficient arguments

 

Please upload my project into your IDE and see if you can get it build/run that when the user selects from the dropdowns the label populates with the correct output from the table.

---
Check out my BB10 Cascades Coding site: BBcascades.com & Cascades Blog: bbcascadescode.tumblr.com

My Built for BlackBerry app: The Dive Plan
Trusted Contributor
Posts: 140
Registered: ‎11-23-2010
My Device: Torch 9800

Re: Running C++ script using QML UI?

Ok so here's what I see wrong with your code, and I'm no C++ wiz kid so if I mess up well I tried.

First of you are trying to send blank values, since in your qml you are sending in1.text and in2.text. Those 2 .text don't exist on DropDown. Might I suggest a little trip to the documentation : https://developer.blackberry.com/cascades/reference/bb__cascades__dropdown.html

 

+ I suggest that you look at how they are doing it in the cookbookqml sample in the dropdown section.

 

You need to send 

 

            onSelectedIndexChanged: {
                var option = in1.at (selectedIndex);
                var option2 = in2.at (selectedIndex);
                total.text = app.clickedButton(option.value, option2.value);

 

and I removed your Global variables in the app.hpp int in1, int in2 and the char read.

 

I then changed your int clickedButton to QString clickedButton or else I was getting the converted value of your char. And voilà.. Don't ask me to explain I sux at C++, still learning.

 

Have fun

 

PS: I have no clue how to add file to the post or else I would of link it to you