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
Eir
Contributor
Posts: 38
Registered: ‎11-28-2011
My Device: Z10
My Carrier: asdf
Accepted Solution

ContactPicker signal connecting

Hello,

 

I cannot connect the signal of a ContactPicker. Here's my code:

 

  ContactPicker *contactPicker = new ContactPicker();
  contactPicker->setMode(ContactSelectionMode::Multiple);

  bool success = QObject::connect(contactPicker,
       SIGNAL(contactsSelected(QList<int> &)),
       this,
       SLOT(onContactsSelected(QList<int> &)));

  if (success) { // Signal was successfully connected.
    contactPicker->open();
  } else { // Failed to connect to signal.
    alert(tr("Didn't connect the picker signal"));
  }

 I had similar issues when connecting the signal of a SystemPrompt, but I resolved it by adding all the (unmentioned) dependencies in the hdd file - I found a working example and saw everything that needs to be included. But for the ContactPicker, I cannot find a working example. Any help? Much appreciated.

 

Thanks.

http://eir3.com
Developer
Posts: 1,524
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: ContactPicker signal connecting

Hi,

 

const and & can be omitted, but they aren't equal to non const reference.

The following should work:

 

Slot definition:

 

void onContactsSelected(const QList<int> &contactIds);

 Connection:

 

QObject::connect(picker, SIGNAL(contactsSelected(QList<int>)),
	         this, SLOT(onContactsSelected(QList<int>)));

 


Andrey Fidrya, @zmeyc on twitter
Eir
Contributor
Posts: 38
Registered: ‎11-28-2011
My Device: Z10
My Carrier: asdf

Re: ContactPicker signal connecting

Thank you, thank you, thank you!

 

To make all clear to anyone looking at this thread in the future, my error was the synthax, the extra &, which I copied from the official BlackBerry Cascades documentation (found here: http://developer.blackberry.com/cascades/reference/bb__cascades__pickers__contactpicker.html). 

 

So, the correct declaration in the header file:

 

void onContactsSelected(QList<int> selectedContacts);

 and the correct code for the connection:

  bool success = QObject::connect(contactPicker,
       SIGNAL(contactsSelected(QList<int>)),
       this,
       SLOT(onContactsSelected(QList<int>)));

 

http://eir3.com
Highlighted
Developer
Posts: 1,524
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: ContactPicker signal connecting

void onContactsSelected(QList<int> selectedContacts);

 The declaration above will also work, but it's better to declare the slot as

 

void onContactsSelected(const QList<int> &contactIds);

I copy-pasted it from NDK header file. Smiley Happy

Not that it matters much though. The Qt containers data is copy-on-write, so the overhead is minimal even when passing the parameter by value.

 


 

If the slot is void onContactsSelected(const QList<int> &contactIds);

both these forms should work:

1) SLOT(onContactsSelected(const QList<int>&)) // this will be automatically simplified by MOC to the bottom one:

2) SLOT(onContactsSelected(QList<int>)) // also ok

 

This one will NOT work because non-constant references are treated differently:

SLOT(onContactsSelected(QList<int>&)) // documentation contains this one

 

In cases 1) and 2) slot method can still be declared as:

void onContactsSelected(const QList<int> &contactIds);

 


Andrey Fidrya, @zmeyc on twitter