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
Posts: 68
Registered: ‎08-16-2012
My Device: BB10 Dev Alpha
My Carrier: NA

Re: ContextActions inside ListItem can not access ContextProperty in QMLDocument

[ Edited ]

I created a minimum project to demostrate my problem, how ever, the reply does not allow to attach files, so i post my code here, hope it can express my problem better:

 

main.qml:

import bb.cascades 1.0

Page {
    content: Container {        
         
        ListView {
            id: accountListView
            objectName: "accountsListView"             

            listItemComponents: [
                ListItemComponent {
                    type: "listItem"
                    StandardListItem{
                        id: accountItem
                        title: ListItemData.username
                    contextActions: [
                            ActionSet {
                                ActionItem {
                                    title: "myAction"
                                    onTriggered: {
                                        //it does not work here.
                                        app.myAction();
                                    }
                                }
                            }
                        ]
                    }
                } 
            ]
            
            function itemType(data, indexPath) {
                return "listItem";
            }
            
        } // end of ListView
    } // end of Container
    
    actions: [
        ActionItem {
            title: "myAction"
            onTriggered: {
                //it works here.
                app.myAction();
            }
        }
    ]
} 

 app.hpp:

#ifndef APP_H
#define APP_H

#include <QObject>

/*!
 * @brief Application GUI object
 */
class App : public QObject
{
    Q_OBJECT
public:
    App();
    Q_INVOKABLE void myAction();
};

#endif // ifndef APP_H

 app.cpp:

#include "app.hpp"

#include <bb/cascades/Application>
#include <bb/cascades/QmlDocument>
#include <bb/cascades/AbstractPane>
#include <bb/cascades/QListDataModel>
#include <bb/cascades/ListView>

using namespace bb::cascades;

App::App()
{
    QmlDocument *qml = QmlDocument::create("main.qml");
    qml->setContextProperty("app", this);
    AbstractPane *root = qml->createRootNode<AbstractPane>();

    QListDataModel<QVariantMap>* listDataModel = new QListDataModel<QVariantMap>();
    QVariantMap map1;
    map1["username"] = "username1";
    listDataModel->append(map1);
    QVariantMap map2;
    map2["username"] = "username1";
    listDataModel->append(map2);
    ListView* accountsListView = root->findChild<ListView*>("accountsListView");
    accountsListView->setDataModel(listDataModel);

    Application::setScene(root);
}


void App::myAction()
{
	qDebug("myAction() is called...");
}

 

 main.cpp (no change):

#include "app.hpp"

#include <bb/cascades/Application>

#include <QLocale>
#include <QTranslator>

using ::bb::cascades::Application;

int main(int argc, char **argv)
{
    //-- this is where the server is started etc
    Application app(argc, argv);
    
    //-- localization support
    QTranslator translator;
    QString locale_string = QLocale().name();
    QString filename = QString( "ListContextActionTest_%1" ).arg( locale_string );
    if (translator.load(filename, "app/native/qm")) {
        app.installTranslator( &translator );
    }
    
    App mainApp;
    
    //-- we complete the transaction started in the app constructor and start the client event loop here
    return Application::exec();
    //-- when loop is exited the Application deletes the scene which deletes all its children (per qt rules for children)
}

 

Developer
Posts: 20
Registered: ‎08-02-2012
My Device: -
My Carrier: SW Developer

Re: ContextActions inside ListItem can not access ContextProperty in QMLDocument

Please check the changes in bold...this works fine for me

 

import bb.cascades 1.0

Page {
content: Container {

ListView {
id: accountListView
objectName: "accountsListView"

listItemComponents: [
ListItemComponent {
type: "listItem"
StandardListItem{
id: accountItem
title: ListItemData.username
contextActions: [
ActionSet {
ActionItem {
title: "myAction"
onTriggered: {
//it does not work here.
accountItem.ListItem.view.myAction();
}
}
}
]
}
}
]

function myAction() {
app.myAction();
}

function itemType(data, indexPath) {
return "listItem";
}

} // end of ListView
} // end of Container

actions: [
ActionItem {
title: "myAction"
onTriggered: {
//it works here.
app.myAction();
}
}
]
}

Developer
Posts: 68
Registered: ‎08-16-2012
My Device: BB10 Dev Alpha
My Carrier: NA

Re: ContextActions inside ListItem can not access ContextProperty in QMLDocument

Thanks very much, it works.
Contributor
Posts: 26
Registered: ‎08-25-2011
My Device: Z10
My Carrier: Bell

Re: ContextActions inside ListItem can not access ContextProperty in QMLDocument

After five hours it's just about time for me to find. Thank you!
New Developer
Posts: 161
Registered: ‎04-12-2010
My Device: Storm
My Carrier: Verizon

Re: ContextActions inside ListItem can not access ContextProperty in QMLDocument

[ Edited ]

Guys this has been a while ago but  I have the very same issue without a solution yet. Same as the original poster here I dont get it to work in a ContextAction, I get the menus to pop but when I click on an ActionItem nothing happens, I tried the suggestion above which is the same as the Bucket sample, lots of permutations but still I don't get the menu to call the ontriggered section,  My code is just about the same as of the original poster here I have a custom ListItemComponent where I'm trying t oget the menus to work.

 

the samples here and on the Bucket sample they use a StandardListItem which I'm not using in my customitemcomponent is that  it???? it only works with a Standard entry???? If this is so .. then it is not availabe for a CustomItem???

 

Any things to look for???

Highlighted
Contributor
Posts: 26
Registered: ‎08-25-2011
My Device: Z10
My Carrier: Bell

Re: ContextActions inside ListItem can not access ContextProperty in QMLDocument

This is working for me.

 

 

ListView {
    id: wineList
    dataModel: ArrayDataModel {
        id: myModel
    }
    listItemComponents: [
        ListItemComponent {
            Container {
                id: wineItem
                layout: StackLayout {
                    orientation: LayoutOrientation.LeftToRight
                }
                Label {
                    text: ListItemData.name
                }
                contextActions: [
                    ActionSet {
                        title: "Contact"
                        ActionItem {
                            title: "Send an Email"
                            imageSource: "asset:///images/add.png"
                            onTriggered: {
                                wineItem.ListItem.view.myAction();
                            }

                        }
                    } // end of ActionSet
                ]
            } // Container

        }
    ]
    onActivationChanged: {
        chosenItem = dataModel.data(indexPath);
    }

    function myAction() {

    }
}
New Developer
Posts: 161
Registered: ‎04-12-2010
My Device: Storm
My Carrier: Verizon

Re: ContextActions inside ListItem can not access ContextProperty in QMLDocument

Bingo!!!! cool man 

 

From all of the permutations I tried the one on your sample is the one I didn't .... e.g. put the id inside the main Container all of the samples I've seen they used a StandardItem and put the id outside,  we always know better after the fact I see it is logical.

Regular Contributor
Posts: 51
Registered: ‎08-07-2013
My Device: blackberry z10
My Carrier: asif

Re: ContextActions inside ListItem can not access ContextProperty in QMLDocument

We cannot use standard list item we can use the customic list listview

for example

hello sir
i can access button in a listview
for example
ListView {
translationY: 00
dataModel: dataModelList
listItemComponents: [
ListItemComponent {
type: "item"
Container {
Label {
text: "Category:"
}
Label {
text: ListItemData.cat_name
}
ImageButton {
id: view_details_btn
defaultImageSource: "asset:///coupon%20list/viewdetail_button.png"
pressedImageSource: "asset:///coupon%20list/viewdetailhover_button.png"
onClicked: {
}
}
}
]
onTriggered: {
var showDetail = productDetailPageID.createObject();
showDetail.myProfileData=dataModel.data(indexPath);
navigationPane.push(showDetail);
}
}
i can access this button.....

New Developer
Posts: 2
Registered: ‎04-17-2014
My Device: Z10
My Carrier: TIM

Re: ContextActions inside ListItem can not access ContextProperty in QMLDocument

[ Edited ]

Hi,
Maybe there is an error in the second qml example

doSometing() instead doSomething()

Smiley Wink