Skip to content

Instantly share code, notes, and snippets.

@40
Created September 19, 2012 22:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 40/3752815 to your computer and use it in GitHub Desktop.
Save 40/3752815 to your computer and use it in GitHub Desktop.
Source Code for Launching BB10 Browser from Cascades App
#include "app.hpp"
#include <bb/cascades/Application>
#include <bb/cascades/QmlDocument>
#include <bb/cascades/AbstractPane>
#include <bps/navigator.h>
using namespace bb::cascades;
App::App()
{
QmlDocument *qml = QmlDocument::create("main.qml");
//-- setContextProperty expose C++ object in QML as an variable
qml->setContextProperty("app", this);
AbstractPane *root = qml->createRootNode<AbstractPane>();
Application::setScene(root);
}
App::launchBrowser(QString url)
{
navigator_invoke(url.toStdString().c_str(), 0);
}
#ifndef APP_H
#define APP_H
#include <QObject>
#include <bps/navigator.h>
/*!
* @brief Application GUI object
*/
class App : public QObject
{
Q_OBJECT
public:
App();
Q_INVOKABLE void launchBrowser(QString url);
};
#endif // ifndef APP_H
import bb.cascades 1.0
//-- create one page with a label and text
Page {
content: Container{
Button{
id: launchButton
text: "Launch Browser"
onClicked: {
app.launchBrowser("http://www.blackberry.com");
}
}
}
}
@NarendraPolasam
Copy link

hi i was trying with same example but getting erros in blackberry 10 cascades
Request you to help me on this

Thank you

@joegege
Copy link

joegege commented May 22, 2013

Yes, this code snippet does work.
Thanks.

@igbanam
Copy link

igbanam commented Jan 14, 2014

You would need an bb::cascades::Invocation object in your App for this to work. This is most likely used in the bps/navigator.h file which is not shown here. The correct way to do this would be

#include <bb/cascades/Invocation>
#include <bb/csacades/InvokeQuery>

bb::cascades::Invocation *m_invoker;
m_invoker = bb::cascades::Invocation::create(
    bb::cascades::InvokeQuery()
    .loc("http://google.com")
    .mimetype("text/plain")
    .parent(this));
connect(m_invoker, SIGNAL(armed()), this, SLOT(onInvokerArmed()));

void ThisClass::onInvokerArmed() {
    m_invoker->trigger("bb.action.OPEN");
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment