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
New Contributor
Posts: 4
Registered: ‎03-26-2013
My Device: None
My Carrier: None

Re: Duplicate actionbar buttons

Fair enough.

 

But as to your previous post, I'm confused.  Just to be totally clear, you are saying we should NOT be doing this:

 

qml->setContextProperty("_object",this);

AbstractPane *root = qml->createRootObject<AbstractPane>();

 

and should instead be doing this:

 

AbstractPane *root = qml->createRootObject<AbstractPane>();

qml->setContextProperty("_object",this);

 

 

Yes?

 

Also, I can't speak for anyone else, but I am not trying to change the placement of an ActionItem, per se.  When a user selects an item from the list view, then a "Next" ActionItem becomes enabled.  When it is pressed, another page with a list view is loaded, and its contents come from a model that is generated in response to the item selected in the previous page's list view.  Pressing "Back" at this point results in duplicate "Next" ActionItems.

 

New Contributor
Posts: 4
Registered: ‎03-26-2013
My Device: None
My Carrier: None

Re: Duplicate actionbar buttons

Just an update on what appears to be a solution to my problem.

 

Recall that ndsmyter (via graymatter) pointed out the importance of the order of calls, i.e. they recommended placing calls to setContextProperty() before the call to createRootObject() to address duplicate ActionItems.  In practice, this appears to be totally correct.  But it's a bit of a connundrum for people like me who want to [re]generate a data model and expose it to QML in response to user actions.  I had placed a setContextProperty() call in a C++ Q_INVOKABLE function to this effect, which of course resulted in a duplicate ActionItem since it gets called after createRootObject().

 

To address duplicate ActionItems versus dynamic model generation/exposition, I indeed placed my calls to setContextProperty() before the call to createRootObject() in the ctor, but I instantiated the second, dynamic data model with an empty list:

 

/* Expose some data to the UI. */

qml->setContextProperty("RoutesModel", new QListDataModel<Route *>(gtfsDB->routesForRegion("...")));

qml->setContextProperty("StopsModel", new QListDataModel<Stop *>(QList<Stop *>())); // <-- added this line

.

.

.

AbstractPane *root = qml->createRootObject<AbstractPane>();

app->setScene(root);

}

 

My Q_INVOKABLE function remained as before:

 

void LocationTest:Smiley SurprisednRouteSelected(const QString &routeID) {
qml->setContextProperty("StopsModel", new QListDataModel<Stop *>(gtfsDB->stopsForRoute(routeID)));
}

 

In my testing so far, this appears to work: I can generate and expose StopsModel dynamically, but I don't get duplicate ActionItems on "Back".  Evidently, registering an empty model before calling createRootObject() is the key.