02-11-2013 01:45 PM - edited 02-11-2013 01:48 PM
I am having a weird problem with my Blackberry Cascades application. I was trying to add a button to actionbar (at the bottom of the application). But when I test it in the Blackberry 10 Dev Alpha simulator (BB10_0_10.261) it seems that I have 2 (and sometimes 3) versions of the same button, as shown in the image below. While there should normally be only 1?
So what I do is adding a button to my page in QML like so:
NavigationPane {
Page {
Container {
layout: StackLayout {
}
ListView {
...
}
}
actions: [
ActionItem {
title: "New Event"
ActionBar.placement: ActionBarPlacement.OnBar // HERE
onTriggered: {
var page = newEventPage.createObject();
navigationPane.push(page);
}
attachedObjects: ComponentDefinition {
id: newEventPage
source: "addEvent.qml"
}
}
]
}
onPopTransitionEnded: {
page.destroy();
}
}
This code does not a lot more than adding a button "New Event" that will link to my "addEvent.qml"
But if I remove (or comment) the line `Actionbar.placement: ActionBarPlacement.OnBar` (marked with `HERE` in the code above), I only get 1 button as was expected. But this button is situated in the overflow menu, while I want it on the ActionBar at the bottom.
All the different versions of the buttons do exactly the same thing (the expected behaviour by the way: opening addEvent.qml).
What I've already tried: "Clean.." and then "Rebuild"; this didn't work. I also tried to move the actions-array to other places, as I thought this could be on the wrong place, but this didn't help either. Removing the application on the simulator, and then reinstalling it.
I also tried it on a different computer, and other simulator, as I thought it could maybe be my computer. But I had the same problem there.
I don't know if this is a bug or not, but I guess I am doing something wrong, since I don't have a lot of experience in Cascades Development. I have looked everywhere, but haven't anybody else with the same problem. I haven't tested it on a real device, because I don't have a BB10 device (yet).
StackOverflow link to this issue: http://stackoverflow.com/questions/14818434/duplic
Solved! Go to Solution.
02-11-2013 04:41 PM
I've seen this issue too and it was quite a head scratcher, turned out that it was a weird bug caused by the placing of a setContext function call in my C++ source. I don't have an example available at the moment to check specifics, but it was something to do with the setContext function call and it's placement in reference the the create root context.
02-11-2013 04:48 PM
I'd look at slog2info -w output, it can tell a lot.
And just as an experiment: what if you add two more Action Items (different titles)? will you have 9 actions in total?
02-12-2013 03:12 AM - edited 02-12-2013 03:45 AM
I will have a look at the slog2info and the placing when I am sitting behind my computer in a little while. But to answer if I get more buttons when I add more actions: yes it does. Not on the action bar as this is limited, but in the overflow I can find a lot more buttons. I tried this with 2 actions (same titles though) before, I thought this could maybe solve my problem, but it didn't.
02-12-2013 04:01 AM
All credit for this answer goes to graymatter for his help (http://supportforums.blackberry.com/t5/Cascades-De
But I will explain what I did to solve the problem. Apparantly the problem was that I used
qml->setContextProperty("model", model);
in my C++ code. And I thought that it didn't make a huge of difference, so I've put this line behind the line
AbstractPane *root = qml->createRootObject<AbstractPane>();
But apparantly it does make a difference, because then you will receive your buttons double.
So to solve the problem, just move the setContextProperty lines before the createRootObject line and everything is solved.
And the problem I had with 3 buttons, seems to be that I had 2 setContextProperty lines of code, behind the createRootObject line. So for every setContextProperty line, the buttons were duplicated.
Should somebody know why this weird thing happens, feel free to mention this.
And to answer the question of BGmot the slog2info log gave no information about this problem.
03-27-2013 06:55 PM
So, what does this mean for populating a data model dynamically? For example, this works, but results in a duplicate Action in the previous view when the user presses "Back":
void LocationTest::onRouteSelected(const QString &routeID) {
qml->setContextProperty("StopsModel", new QListDataModel<Stop*>(gtfsDB->stopsForRoute(routeI D)));
}
We can't possibly be restricted to "frontloading" our data models...can we?
My thought was to have a stopsModel instance variable of type QListDataModel<Stop *> *. Then I could setContextProperty using the empty model once prior to calling createRootObject , and in my function simply append the new values to the model. But properly declaring and instantiating it is proving to be far more difficult than I thought it would!
Anyways, is that the right idea? Or is there some other way to dynamically load models into views without causing duplicate action items?
03-27-2013 07:02 PM - edited 03-27-2013 07:03 PM
You could declare the model as a property of another class and export an instance of that class to QML once.
In QML it will be possible to access the model as a property. It will be also possible to replace the model with another model in C++ code if needed.
03-28-2013 10:10 AM - edited 03-28-2013 12:15 PM
Hi all, this seems to be a Cascades bug happening when you try to change the ActionBar.placement for an ActionItem after the page was created. As a workaround to this issue until it is fixed, please refrain from changing the ActionItem.placment after the page is created, i.e. (in this case) from using "setcontextproperty" before the AbstractPane is created.
qml->setContextProperty("_object",this);
AbstractPane *root = qml->createRootObject<AbstractPane>();
Another note to developers facing this issue during runtime: from a design point of view, it is not recommended that the application switches where the ActionItems are placed after the page is created. You can enable/disable ActionItems if desired, but changing the ActionItems placement will likely cause confusion to the user and affect the user experience.
Hope that helps!
Samar Abdelsayed - Application Development Consultant - BlackBerry
Did this answer your quetion? Please accept post as solution.
Please refrain from posting new questions in solved threads.
Found a bug? Report it using the Issue Tracker
03-28-2013 12:04 PM
03-28-2013 12:12 PM