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
ndsmyter
Posts: 648
Registered: ‎09-26-2012
My Device: Limited Edition Z10, Playbook 16GB/32GB, Dev Alpha A/B/C
Accepted Solution

Duplicate actionbar buttons

[ Edited ]

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?

TooManyButtons

 

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/duplicate-actionbar-buttons-in-blackberry-cascades



A like is always appreciated,
but a nomination for BB Elite even more :-)
You can also contact me on Twitter: @ndsmyter
Please use plain text.
Contributor
graymatter
Posts: 28
Registered: ‎07-29-2010
My Device: Torch 9850

Re: Duplicate actionbar buttons

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.

Please use plain text.
Developer
BGmot
Posts: 1,068
Registered: ‎11-24-2011
My Device: PlayBook

Re: Duplicate actionbar buttons

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?

Please use plain text.
Developer
ndsmyter
Posts: 648
Registered: ‎09-26-2012
My Device: Limited Edition Z10, Playbook 16GB/32GB, Dev Alpha A/B/C

Re: Duplicate actionbar buttons

[ Edited ]

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.



A like is always appreciated,
but a nomination for BB Elite even more :-)
You can also contact me on Twitter: @ndsmyter
Please use plain text.
Developer
ndsmyter
Posts: 648
Registered: ‎09-26-2012
My Device: Limited Edition Z10, Playbook 16GB/32GB, Dev Alpha A/B/C

Re: Duplicate actionbar buttons

All credit for this answer goes to graymatter for his help (http://supportforums.blackberry.com/t5/Cascades-Development/Duplicate-actionbar-buttons/m-p/2157001#...).

 

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.



A like is always appreciated,
but a nomination for BB Elite even more :-)
You can also contact me on Twitter: @ndsmyter
Please use plain text.
New Contributor
Urthas
Posts: 4
Registered: ‎03-26-2013
My Device: None

Re: Duplicate actionbar buttons

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(routeID)));
}

 

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?

Please use plain text.
Developer
Zmey
Posts: 1,512
Registered: ‎12-18-2012
My Device: PlayBook, Z10, DAC

Re: Duplicate actionbar buttons

[ Edited ]

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.

 


Andrey Fidrya, @zmeyc on twitter
Please use plain text.
BlackBerry Development Advisor
sabdelsayed
Posts: 249
Registered: ‎08-17-2012
My Device: BlackBerry Z10 and Q10

Re: Duplicate actionbar buttons

[ Edited ]

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!

@SamarAbdelsayed

Did this answer your question? Please accept post as solution.
Please refrain from posting new questions in solved threads.
Found a bug? Report it using the Issue Tracker
Please use plain text.
New Contributor
Urthas
Posts: 4
Registered: ‎03-26-2013
My Device: None

Re: Duplicate actionbar buttons

Well, I don't seem to be able to declare a model at all. If, in my header, I write:

namespace bb { namespace cascades {class QListDataModel<QObject *>;} }
.
.
.
bb::cascades::QListDataModel<QObject *> *model;

then I get

error: 'QListDataModel' is not a template
error: 'bb::cascades::QListDataModel' is not a template

but if I instead write:

namespace bb { namespace cascades {class QListDataModel;} }
.
.
.
bb::cascades::QListDataModel *model;

then I get

error: template argument required for 'class QListDataModel'
error: invalid use of template-name 'bb::cascades::QListDataModel' without an argument list

I don't know what to make of these apparently conflicting sets of errors.
Please use plain text.
BlackBerry Development Advisor
sabdelsayed
Posts: 249
Registered: ‎08-17-2012
My Device: BlackBerry Z10 and Q10

Re: Duplicate actionbar buttons

Hi Urthas, your post doesn't seem related to this issue. Please start another forum post.
@SamarAbdelsayed

Did this answer your question? Please accept post as solution.
Please refrain from posting new questions in solved threads.
Found a bug? Report it using the Issue Tracker
Please use plain text.