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. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Cascades Development

Reply
Regular Contributor
marcossit
Posts: 81
Registered: ‎07-19-2012
My Carrier: Movistar-Venezuela
Accepted Solution

Button Exit

Goodnight, you create an Exit button in my app with this code but I closed QML will enter it wrong? or there will be another code that can with a navigation button closing my app.

 

            ActionItem {
                title: "Exit"
                imageSource: "asset:///images/icons/exit.png"
                ActionBar.placement: ActionBarPlacement.OnBar
                onTriggered: {
                    _app.exitApp();
                   }

 

 

Download my App for BB10 http://appworld.blackberry.com/webstore/content/134103/
Please use plain text.
Developer
greenback
Posts: 448
Registered: ‎10-17-2010

Re: Button Exit

@marcossit

 

To implement the quit function in xml.

 

3 Files are automatically generated in the src folder with you create new Cascades Project 

  1. main.cpp
  2. [app].cpp
  3. [app].hpp

Open up [app.cpp]

 

Under 

locate the contstructor

using namespace bb::cascades;
App::App(bb::cascades::Application *app)
: QObject(app)
{

    // create scene document from main.qml asset
    // set parent to created document to ensure it exists for the whole application lifetime
    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);
}

 

IMPORTANT 

(bb::cascades::Application *app)


If not already there make sure bb::cascades::Application *app is between the parenthesis.



How To Force Quit Application from QML

You will need to execute the quit() method.
Reference: https://developer.blackberry.com/cascades/reference/bb__cascades__application.html


main.qml

Application.quit();

 
And in your code specifically, this will work:

 

 ActionItem {
                title: "Exit"
                imageSource: "asset:///images/icons/exit.png"
                ActionBar.placement: ActionBarPlacement.OnBar
                onTriggered: {
                    Application.quit();
                   }

 
That's it. Best of luck to you in your development!

Please LIKE & ACCEPT AS SOLUTION

:Rockon:



Please use plain text.
New Developer
shaii
Posts: 17
Registered: ‎05-09-2011
My Carrier: pelephone

Re: Button Exit

@greenback I dont have Application context when i try to use it in QML page (auto-complete also doesnt detect it) do u know why it is?

 

@marcossit i manage to do it by connecting the Qt.quit signal to the app quit slot in c++

 

just paste this code in your [project name class].cpp after qml pointer initialization

QObject

::connect(qml->documentContext()->engine(), SIGNAL(quit()), app, SLOT(quit()));

Please use plain text.
New Developer
shaii
Posts: 17
Registered: ‎05-09-2011
My Carrier: pelephone

Re: Button Exit

@greenback i think i just noticed your mistake... you forget to set the app as a context property...
qml->setContextProperty("Application", this); is missing from your code
Please use plain text.