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: 1,008
Registered: ‎12-12-2010
My Device: Passport (Red Limited Edition)
My Carrier: Mobile Vikings
Accepted Solution

Can't access ActionItem in contextActions in a ListItemComponent

Hi,

 

I have several ListItemComponents, each with their own contextActions. However, I can't access them. What am I doing wrong?

 

TabbedPane {
    id: tabbedPane
    showTabsOnActionBar: true       
    Menu.definition: MenuDefinition {
	    actions: [
	        ActionItem {
	            objectName: "scanItem"
	            title: "Scan"
	        },
	        ActionItem {
	            objectName: "aboutItem"
	            title: "About"
	        }
	    ]
	}
    
    Tab {
        title: "Grid"
        imageSource: "asset:///images/grid.png"
        content: NavigationPane {
            objectName: "gridNavigationPane"
            peekEnabled: false
            backButtonsVisible: false
	        Page {
	            content: Container {
	                background: backgroundPaint.imagePaint
	                layout: StackLayout {}
	                ListView {
	                    objectName: "coverListView"
	                    layout: GridListLayout {
	                        columnCount: 2    
	                        horizontalCellSpacing: 6
	                    }
	    			    listItemComponents: [
	    			        ListItemComponent {
	    			            type: "normal-read"
	    			            Container {
		                            layout: StackLayout {
		                                orientation: LayoutOrientation.TopToBottom
		                            }
		                            ImageView {
		    			            	objectName: "listItemComponent"
		    			                imageSource: ListItemData.imagePath
		    			                scalingMethod: ScalingMethod.AspectFit
		    			                horizontalAlignment: HorizontalAlignment.Center
		                            }
		                            Label {
		                                text: ListItemData.title
		                                horizontalAlignment: HorizontalAlignment.Center
		                                textStyle {
	                                        base: SystemDefaults.TextStyles.SmallText
	                                        color: Color.create(0.9, 0.9, 0.9)
	                                    }
		                            }	                        
            	    	            contextActions: [
            	    	                ActionSet {				                      
            	    	                    ActionItem {
            	    	                        objectName: "normal1OpenAction"
            	    	                        title: "Open"
            	    	                        imageSource: "asset:///images/openbook.png"
            	    	                    }
            	    	                    ActionItem {
            	    	                        objectName: "normal1MarkAsFavorite"
            	    	                        title: "Mark as favorite"
            	    	                        imageSource: "asset:///images/favorite.png"
            	    	                    }
            	    	                    ActionItem {
            	    	                        objectName: "normal1MarkAsUnread"
            	    	                        title: "Mark as unread"
            	    	                        imageSource: "asset:///images/unread.png"
            	    	                    }
            	    	                    ActionItem {
            	    	                        objectName: "normal1ShareAction"
            	    	                        title: "Share"
            	    	                        imageSource: "asset:///images/share.png"
            	    	                    }
            	    	                    DeleteActionItem {
            	    	                        objectName: "normal1DeleteAction"
            	    	                        title: "Delete"
            	    	                        imageSource: "asset:///images/trash.png"
            	    	                    }
            	    	                }
            	    	            ]
		                        }
	    			        }
	    			    ]
	                }
	            }
	        }
        }
    }
    
    Tab {
        title: "List"
        imageSource: "asset:///images/list.png"
        content: Page {
            content: ListView {
                objectName: "listView"
                listItemComponents: [
			        ListItemComponent {
			            type: "image"
			            StandardListItem {
                            imageSource: ListItemData.imagePath
                            title: ListItemData.title
                        }        
			        }
			    ]
            }
        }
    } 
        
    Tab {
        title: "Settings"
        imageSource: "asset:///images/settings.png"
        content: Page {
            content: Container {
                background: backgroundPaint.imagePaint
            }    
        }
    } 
    attachedObjects: [
        ImagePaintDefinition {
            id: backgroundPaint
            imageSource: "asset:///images/shelfbackground.png"
            repeatPattern: RepeatPattern.XY
        }
    ]
}

 This is my code for accessing the ActionItems.

 

QmlDocument *qmlDocument = QmlDocument::create("asset:///main.qml");
    if (!qmlDocument->hasErrors())
    {
qmlDocument->setContextProperty("comicsApp", this);
rootPane = qmlDocument->createRootObject<TabbedPane>();
ActionItem* actionItem = rootPane->findChild<ActionItem*>("normal1OpenAction");
	connect(actionItem, SIGNAL(triggered()), this, SLOT(handleOpenComic()));
}

 I am connecting other QML objects their signals with slots in the same way, but this keeps failing. Does anyone have a clue why?

-------------------------------------------
BlackBerry Certified Builder for Native Application Development -- Proud member of the Belgian BlackBerry Developer group
Samples: Park in Ghent
Feeling generous? Nominate me for BB Elite member!
Developer
Posts: 1,008
Registered: ‎12-12-2010
My Device: Passport (Red Limited Edition)
My Carrier: Mobile Vikings

Re: Can't access ActionItem in contextActions in a ListItemComponent

I ended up writing a ListItemProvider in C++ code. Works like a charm!

-------------------------------------------
BlackBerry Certified Builder for Native Application Development -- Proud member of the Belgian BlackBerry Developer group
Samples: Park in Ghent
Feeling generous? Nominate me for BB Elite member!