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: 275
Registered: ‎02-05-2010
My Device: Blackberry Z10
My Carrier: Bouygues Telecom
Accepted Solution

ListView long press andd cpp function

Hi,

Here's my code to display a ListView. When the user long press an item, a context menu shows up to share or copy the selected item value.
Sharing works great but copy does not.
lab.text is populated with the good value but the problem is with 'funText'. I can't access my c++ functions here !
Any idea how to solve this issue ?

Thanks,
Laurent

 

ListView {
  id:smileysList
  leftPadding:15
  dataModel: smileysModel
  
  attachedObjects: [                
    SmileysModel {
      id: smileysModel          
      jsonAssetPath: "app/native/assets/smileys.json"  
      filter: "Smiling, happy"          
    }
  ]  
  
  listItemComponents: [
    ListItemComponent {
    
      Container{
        Label {
          id:lab
          text: ListItemData.title
          contextActions: [
            ActionSet {
              actions: [    
                InvokeActionItem {                  
                  title:'Share'
                  imageSource: "asset:///images/shareblue.png"                  
                  query {
                    mimeType: "text/plain"
                    invokeActionId: "bb.action.SHARE"        
                  }
                  onTriggered: {                    
                    data = lab.text;            
                  }
                },
                ActionItem {
                  title: "Copy"              
                  imageSource: "asset:///images/copy.png"                  
                  onTriggered: {
                    funText.copyToClipboard(lab.text);          
                  }              
                }
              ]
            }
          ]
        }
        
        Divider{}
      }
      
    }
  ]
}

 

Twitter : @LaurentKP
My apps
Developer
Posts: 17,011
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: ListView long press andd cpp function

ListItems reside in a different context, they cannot directly access the outer qml.
You can access the ListView from it and define functions or properties in there:
itemID.ListItem.view
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 275
Registered: ‎02-05-2010
My Device: Blackberry Z10
My Carrier: Bouygues Telecom

Re: ListView long press andd cpp function

Thank you Simon,

something like that ?

 

ListView {
  id:smileysList
  leftPadding:15
  dataModel: smileysModel
  
  attachedObjects: [                
    SmileysModel {
      id: smileysModel          
      jsonAssetPath: "app/native/assets/smileys.json"  
      filter: "Smiling, happy"          
    }
  ]  
  
  listItemComponents: [
    ListItemComponent {
	  
    
      Container{
		id:myListItem
        Label {
          id:lab
          text: ListItemData.title
          contextActions: [
            ActionSet {
              actions: [    
                InvokeActionItem {                  
                  title:'Share'
                  imageSource: "asset:///images/shareblue.png"                  
                  query {
                    mimeType: "text/plain"
                    invokeActionId: "bb.action.SHARE"        
                  }
                  onTriggered: {                    
                    data = lab.text;            
                  }
                },
                ActionItem {
                  title: "Copy"              
                  imageSource: "asset:///images/copy.png"                  
                  onTriggered: {
					myListItem.ListItem.view.copyToC(lab.text);          
                  }              
                }
              ]
            }
          ]
        }
        
        Divider{}
      }
      
    }
  ]
  
  function copyToC(text){
    _funtext.copyToClipboard(text);
  }
  
}

 

Twitter : @LaurentKP
My apps
Developer
Posts: 17,011
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: ListView long press andd cpp function

i think you have to move the id to ListItemComponent, not the container. Otherwise, yes, that would be the concept.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 275
Registered: ‎02-05-2010
My Device: Blackberry Z10
My Carrier: Bouygues Telecom

Re: ListView long press andd cpp function

Yes you're right, I'll try that later today and will get back to you. Thanks.

Twitter : @LaurentKP
My apps
Developer
Posts: 275
Registered: ‎02-05-2010
My Device: Blackberry Z10
My Carrier: Bouygues Telecom

Re: ListView long press andd cpp function

I got an error :

ReferenceError: Can't find variable: myListItem

Twitter : @LaurentKP
My apps
Developer
Posts: 275
Registered: ‎02-05-2010
My Device: Blackberry Z10
My Carrier: Bouygues Telecom

Re: ListView long press andd cpp function

and if I put id:myListItem in the Container I got the error :

TypeError: Result of expression 'funText.copyToClipboardB'
[undefined] is not a function.

Twitter : @LaurentKP
My apps
Highlighted
Developer
Posts: 275
Registered: ‎02-05-2010
My Device: Blackberry Z10
My Carrier: Bouygues Telecom

Re: ListView long press andd cpp function

OK sorry it's my mistake the code above is working !!! 

Twitter : @LaurentKP
My apps