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
Highlighted
New Contributor
Posts: 6
Registered: ‎10-12-2012
My Device: bb10-dev
My Carrier: Initial developer

Need your help_integrating c++ and qml

[ Edited ]

Hi everyone;
I really need your help guys and this my problem:
I want to combine 2 project in 1,
I have to lunch a screen that contain " (augmented reality technologies)-->(work)" when I click in a button created in another qml page(bridge.qml) ,
I'm sure that the problem is in bridge.cpp (and the method is called "ont") but I don't know how to deal with it :/
this my code please make a look a it :
*****************************************************************************************************************************
main.cpp
*****************************************************************************************************************************
// Default empty project template
#include <bb/cascades/Application>
#include <bb/cascades/QmlDocument>
#include <bb/cascades/AbstractPane>

#include <QLocale>
#include <QTranslator>
#include "Bridge.hpp"

using namespace bb::cascades;

int main(int argc, char **argv)
{
Application app(argc, argv);
QTranslator translator;
QString locale_string = QLocale().name();
QString filename = QString( "Bridge_%1" ).arg( locale_string );
if (translator.load(filename, "app/native/qm")) {
app.installTranslator( &translator );
}
new Bridge(&app);
return Application::exec();
}

*****************************************************************************************************************************
Bridge.cpp
*****************************************************************************************************************************
// Default empty project template
#include "Bridge.hpp"
#include "SimpleARBrowser.hpp"
#include <bb/cascades/Application>
#include <bb/cascades/QmlDocument>
#include <bb/cascades/AbstractPane>

 

using namespace bb::cascades;
int Bridge:Smiley Surprisednt( int argc, char **argv)
{
Application app(argc, argv);
QTranslator translator;
QString locale_string = QLocale().name();
QString filename = QString( "SimpleARBrowser_%1" ).arg( locale_string );
if (translator.load(filename, "app/native/qm")) {
app.installTranslator( &translator );
}
new SimpleARBrowser(&app);
return Application::exec();}

Bridge::Bridge(bb::cascades::Application *app)
: QObject(app)
{
QmlDocument *qml = QmlDocument::create("asset:///bridge.qml").parent(this);
AbstractPane *root = qml->createRootObject<AbstractPane>();
Button *newButtons = root->findChild<Button*>("b");
if (newButtons)
newButtons->setProperty("text", "button controlled");
bool success = Button::connect(newButtons, SIGNAL( clicked()), this,SLOT(ont(*app->argc(),*app->argv())));
Q_ASSERT(success);
app->setScene(root);
}
******************************************************************************************************************************
Bridge.hpp
*****************************************************************************************************************************
// Default empty project template
#ifndef Bridge_HPP_
#define Bridge_HPP_
#include <bb/cascades/Button>
#include <QObject>


namespace bb { namespace cascades { class Application; }}

class Bridge : public QObject
{
Q_OBJECT
public:
Bridge(bb::cascades::Application *app);
virtual ~Bridge() {}
public Q_SLOTS:
int ont(int argc, char **argv);
};
#endif /* Bridge_HPP_ */
*****************************************************************************************************************************
SimpleARBrowser.hpp
*****************************************************************************************************************************
// Default empty project template
#ifndef SimpleARBrowser_HPP_
#define SimpleARBrowser_HPP_

#include <QObject>
#include "ArchitectView.h"

namespace bb { namespace cascades { class Application; }}

class SimpleARBrowser : public QObject
{
Q_OBJECT
public:
SimpleARBrowser(bb::cascades::Application *app);
virtual ~SimpleARBrowser();

private:
ArchitectView *view;

void loadTestFile();
void loadPois();

void simulateLocation(double latitude, double longitude);

public slots:
void urlWasInvoked(const QString &);
};

#endif /* SimpleARBrowser_HPP_ */

*************************************************************************************************************
SimpleARBrowser.cpp
***************************************************************************************************************
// Default empty project template
#include "SimpleARBrowser.hpp"
#include "Placemark.h"

#include <stdlib.h>
#include <unistd.h>

#include <QDebug>

#include <bb/cascades/Application>
#include <bb/cascades/QmlDocument>
#include <bb/cascades/AbstractPane>
#include <bb/cascades/CustomControl>
#include <bb/cascades/Page>
#include <bb/cascades/Container>
#include <bb/cascades/StackLayout>
#include <bb/cascades/Color>

using namespace bb::cascades;


SimpleARBrowser:Smiley FrustratedimpleARBrowser(bb::cascades::Application *app)
: QObject(app)
{
// Check device
if (!ArchitectView::isDeviceSupported()) {
qCritical() << "Fatal Error - device not supported";
Application::exit(-1);
}

// create scene document from main.qml asset
// set parent to created document to ensure it exists for the whole application lifetime
qmlRegisterType<ArchitectView>("wt.architect", 1, 0, "ArchitectView");
QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);

// create root object for the UI
AbstractPane *root = qml->createRootObject<AbstractPane>();
// set created root object as a scene
app->setScene(root);

/*
* Initialization of the ArchitectView component
*/
view = root->findChild<ArchitectView *>("archView");
view->initialize("whatever+nevermind");

QObject::connect(view,
SIGNAL(urlWasInvoked(const QString &)),
this, SLOT(urlWasInvoked(const QString &)));

qDebug("ArchitectView initialized");

/*
* Ready to load test data.
*/
loadTestFile();
loadPois();
simulateLocation(35.742054, 10.666901);
}

SimpleARBrowser::~SimpleARBrowser() {
delete view;
view = NULL;
qDebug() << "App Destructed";
}

void SimpleARBrowser::loadTestFile() {
view->load("asset:///testfile.html");
}

void SimpleARBrowser::loadPois() {
QStringList jsonArray;
Placemark p = {
QString("P%1").arg(QString::number(1)),
//QString("POI #%1").arg(QString::number(i)),
QString("Sfax"),
QString("sfax !"),
1, {
34.75064 + ((float)rand() / (float)RAND_MAX - .5) / 500 ,
10.771271 + ((float)rand() / (float)RAND_MAX - .5) / 500
}
};
jsonArray << formatJson(p);

Placemark p1 = {
QString("P%2").arg(QString::number(2)),
//QString("POI #%1").arg(QString::number(i)),
QString("Sousse"),
QString("sousse !"),
2, {
35.742054 + ((float)rand() / (float)RAND_MAX - .5) / 500 ,
10.666901 + ((float)rand() / (float)RAND_MAX - .5) / 500
}
};
jsonArray << formatJson(p1);


QString jsCommand = jsonArray.join(", ").prepend("newData('[").append("]');");
qDebug() << "Javascript command: " << jsCommand;
view->callJavascript(jsCommand);
}

void SimpleARBrowser::simulateLocation(double latitude, double longitude) {
view->setUseInjectedLocation(true);
qDebug() << "SimpleARBrowser::simulateLocation() -> Lat: " << latitude << " lon: " << longitude;
qDebug() << "SimpleARBrowser::simulateLocation() -> injection is " << view->isUsingInjectedLocation();
view->injectLocation(latitude, longitude, 35);
}

void SimpleARBrowser::urlWasInvoked(const QString &url) {
view->setUseInjectedLocation(!view->isUsingInjectedLocation());
qDebug() << "opening URL " << url; // -> open detail view
}
*****************************************************************************************************************************
bridge.qml
*****************************************************************************************************************************
import bb.cascades 1.0


Page {
Button {
objectName: "b"
text: "hii"
}
}

*****************************************************************************************************************************
main.qml
*****************************************************************************************************************************
import bb.cascades 1.0
import wt.architect 1.0

Page {
content: ArchitectView {
id: archView
objectName: "archView"
}
}
************************************

waiting for your solutions ,thk u Smiley Happy