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
bcs925
Posts: 262
Registered: ‎07-13-2012
My Device: PlayBook, DA B, DA C, LE Z10 #102, Q10, Z30
My Carrier: T-Mobile

Re: Running C++ script using QML UI?

 

To upload your file, zip the project (so all the folders are in one file) and use the attachments to the right of the dialog box for replying (red circle in image below):

 

AttachBBForum.png

 

Or feel free to email it to me at bcs925@yahoo.com

 

I would really like to see what you did because I tried to do exactly what you described but I get build errors.  My plan once all this is straightened out is to write up a tutorial explaining each piece so anyone else in my shoes can reference my example with full explanations of every step.  Thanks again for your help.

 

 

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

My Built for BlackBerry app: The Dive Plan
Please use plain text.
Developer
bcs925
Posts: 262
Registered: ‎07-13-2012
My Device: PlayBook, DA B, DA C, LE Z10 #102, Q10, Z30
My Carrier: T-Mobile

Re: Running C++ script using QML UI?

Thanks again to everyone that helped me with this, especially AllSystemGo who was a HUGE help

 

In case others were curious here's the code that ended up working (and is pretty easy to follow now that I see the solution)...

 

app.hpp:

#ifndef APP_H
#define APP_H

#include <QtCore/QObject>
#include <QtCore/QMetaType>

#include <bb/cascades/Event>
#include <bb/cascades/UiObject>
#include <bb/cascades/Control>
#include <QObject>


class App: public QObject {

Q_OBJECT


public:
App();

Q_INVOKABLE QString clickedButton(int in1, int in2);

};

#endif // ifndef APP_H

 app.cpp:

#include <bb/cascades/Application>
#include <bb/cascades/QmlDocument>
#include <bb/cascades/AbstractPane>

#include "app.hpp"

using namespace bb::cascades;

App::App() {

    QmlDocument *qml = QmlDocument::create("main.qml");
    qml->setContextProperty("app", this);

    AbstractPane *root = qml->createRootNode<AbstractPane>();
    Application::setScene(root);
}

QString App::clickedButton(int in1, int in2)
{
QString reading;

    if (in1 == 1 && in2 == 1)
    	reading = 'A';
    else if (in1 == 1 && in2 == 2)
    	reading = 'B';
    else if (in1 == 1 && in2 == 3)
    	reading = 'C';
    else if (in1 == 2 && in2 == 1)
    	reading = 'D';
    else if (in1 == 2 && in2 == 2)
    	reading = 'E';
    else if (in1 == 2 && in2 == 3)
    	reading = 'F';
    else if (in1 == 3 && in2 == 1)
    	reading = 'G';
    else if (in1 == 3 && in2 == 2)
    	reading = 'H';
    else if (in1 == 3 && in2 == 3)
    	reading = 'I';

        return reading;

}

 main.qml:

import bb.cascades 1.0

Page {
    content: Container {
        layout: StackLayout {
        }
        ImageView {
            id: imageViewID
            imageSource: "asset:///images/Table_Example.jpg"
        }
        DropDown {
            id: in1
            objectName: "in1"
            title: "Vertical Value?"
            selectedIndex: SelectedIndexNone
            onSelectedIndexChanged: {
                var option = in1.at(in1.selectedIndex).value;
              
                if (in2.selectedIndex == -1 ) {
                    var option2 = 0
                }
                else {
                    var option2 = in2.at(in2.selectedIndex).value;
                }

                total.text = app.clickedButton(option, option2);
            }
            Option {
                text: "1"
                value: 1
            }
            Option {
                text: "2"
                value: 2
            }
            Option {
                text: "3"
                value: 3
            }
        }
        DropDown {
            id: in2
            objectName: "in2"
            title: "Horizontal Value?"
            //selectedIndex: 0
            onSelectedIndexChanged: {
               var option2 = in2.at(in2.selectedIndex);
                
                if (in1.selectedIndex == -1 ) {
                    var option = 0
                }
                else {
                    var option = in1.at(in1.selectedIndex);
                }

                total.text = app.clickedButton(option.value, option2.value);
            } //have my C++ run here
            Option {
                text: "1"
                value: 1
            }
            Option {
                text: "2"
                value: 2
            }
            Option {
                text: "3"
                value: 3
            }
        }
        Label {
            id: total
            objectName: "total"
            text: ""
        }
    }
}

 

 

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

My Built for BlackBerry app: The Dive Plan
Please use plain text.