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
Posts: 188
Registered: ‎07-19-2012
My Device: Z10 Limited Edition and Dev Alpha C
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();
                   }

 

 


Follow me in Twitter:

@Marcossit

BBM Channel:

MarcossitDev: C0002C366  

DeviceSuite For BlackBerry 10:

Link to Download DeviceSuite:

Support was successful? Accept as Solution and click on:


Developer
Posts: 610
Registered: ‎10-17-2010
My Device: (BlackBerry Z10)-> Q10/Passport Dual Use

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



Highlighted
New Developer
Posts: 17
Registered: ‎05-09-2011
My Device: 9700
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()));

New Developer
Posts: 17
Registered: ‎05-09-2011
My Device: 9700
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