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
Developer
Posts: 79
Registered: ‎02-04-2013
My Device: Z10 LE
My Carrier: Simobil
Accepted Solution

ActionItem and SystemToast

[ Edited ]

Hi guys,

 

I'm just wondering, how to make(in C++) an application menu(the one on top) with actionItem which shows SystemToast on triggered.  (Not much into C++ though, so be kind

 

So far I've done this, but I don't know what  am I missing ?

 

In main.cpp:

void App::showToast() {
	SystemToast *toast = new SystemToast(this);
    toast->setBody("bla bla bla");
    toast->show();
}

void App::handleAction()
{
    	showToast();

}

int main(int argc, char **argv)
{
    Application app(argc, argv);
    QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(&app);
    AbstractPane *root = qml->createRootObject<AbstractPane>();
    app.setScene(root);

    Menu *menu = new Menu;
                    ActionItem *actionOne = ActionItem::create()
                                            .title("About");
                    menu->addAction(actionOne);
                    Application::instance()->setMenu(menu);
    bool res = QObject::connect(actionOne, SIGNAL(triggered()), menu, SLOT(handleAction()));
    Q_ASSERT(res); // when this is uncomented application doesn't start
    Q_UNUSED(res);



    return Application::exec();


}

 When this line is uncommented, application doesn't start.

Q_ASSERT(res);

 

In App.hpp:

void showToast();
public slots:
    void handleAction();

 

 

Developer
Posts: 76
Registered: ‎02-08-2013
My Device: z10
My Carrier: rogers

Re: ActionItem and SystemToast

Instead of this:

 bool res = QObject::connect(actionOne, SIGNAL(triggered()), menu, SLOT(handleAction()));

 Try this:

 bool res = QObject::connect(actionOne, SIGNAL(triggered()), this, SLOT(handleAction()));

 Cheers,

Eric

Developer
Posts: 79
Registered: ‎02-04-2013
My Device: Z10 LE
My Carrier: Simobil

Re: ActionItem and SystemToast

This was the first thing, I already tried.  It throws error:  unsupported use of "this"

Developer
Posts: 76
Registered: ‎02-08-2013
My Device: z10
My Carrier: rogers

Re: ActionItem and SystemToast

Try placing the connect call in your class constructor to use 'this'.

Developer
Posts: 79
Registered: ‎02-04-2013
My Device: Z10 LE
My Carrier: Simobil

Re: ActionItem and SystemToast

Still getting:  invalid use of 'this' in non-member function

Developer
Posts: 79
Registered: ‎02-04-2013
My Device: Z10 LE
My Carrier: Simobil

Re: ActionItem and SystemToast

Ok, I've managed to solve it. All the time I was working in main.cpp, moved everything to App.cpp and finally it works.