10-12-2012 01:09 AM
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();
}
Solved! Go to Solution.
10-12-2012 02:53 AM
@marcossit
To implement the quit function in xml.
3 Files are automatically generated in the src folder with you create new Cascades Project
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(th is);
// 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/referenc
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![]()
11-12-2012 04:20 PM
@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()));
11-12-2012 04:27 PM