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
jessica99327
Posts: 84
Registered: ‎04-22-2013
My Device: BB 10 Dev
My Carrier: Simulator
Accepted Solution

How to get number and name from Contact Picker

Hi all,

I got the Contact Picker working but I have no idea how to retrieve the selected contact number and name.

Are there any attributes that I can put in like contactId.value() to retrieve it or there's any other way?

 

Thanks in advance.

ImageButton{
                    defaultImageSource: "asset:///images/bluebutton.png"
                    onClicked: {
                        contactPicker.open();
                    }
                    attachedObjects: [
                        ContactPicker {
                            id: contactPicker
                            onContactSelected: {
                                result.text = "You chose contact: " + contactId;
                            }
                        }
                    ]

                }

                Label {
                    id: result
                    text: "You chose contact: "
                }

 

Please use plain text.
Developer
SumiGhosh
Posts: 435
Registered: ‎09-20-2011
My Device: Z10 LE, Playbook, DevAlpha C, 9900, 9380
My Carrier: Vodafone

Re: How to get number and name from Contact Picker

Please use plain text.
Developer
jessica99327
Posts: 84
Registered: ‎04-22-2013
My Device: BB 10 Dev
My Carrier: Simulator

Re: How to get number and name from Contact Picker

I'm sorry I'm kind of new to this.

But can i just write this in qml or I need to open a new class in c++?

Please use plain text.
Developer
nareshkodumuri
Posts: 125
Registered: ‎04-28-2012
My Device: BlackBerry 9800
My Carrier: BlackBerry

Re: How to get number and name from Contact Picker

Hi,

 

      You can get the contact name and phone number like this,

ImageButton{
                    defaultImageSource: "asset:///images/bluebutton.png"
                    onClicked: {
                        contactPicker.open();
                    }
                    attachedObjects: [
                        ContactPicker {
                            id: contactPicker
                            onContactSelected: {
                                result.text = "You chose contact: " + contactId;
// call a cpp method to get the details

app.getDetails(contactId); } } ] } Label { id: result text: "You chose contact: " }

 cpp code:

 

void ContactDetails(ContactId id)
{
Contact contact_info = m_contactService->contactDetails(id);

	QString firstName = contact_info.firstName();
	QString lastname = contact_info.lastName();
		QList<ContactAttribute> phoneno_list = contact_info.phoneNumbers();

	QStringList no_s;


	foreach(ContactAttribute attr, phoneno_list)
	{
	    no_s << attr.value();
	}
}

 You can get contact details like this.

 

Regards,

Naresh Kodumuri.

Please use plain text.
Developer
jessica99327
Posts: 84
Registered: ‎04-22-2013
My Device: BB 10 Dev
My Carrier: Simulator

Re: How to get number and name from Contact Picker

Hi,

I was trying out the way you mentioned above but keep hitting the error of ContactService was not declared in scope.

I've included the libs in the pro file and give access in the bar descriptor file but still unable to solve it.

Can i know where is the mistakes?

#include "Contact.hpp"
#include <bb/pim/contacts/ContactService>
#include <bb/pim/contacts/Contact>
#include <qDebug>



Contact::Contact()
{
//	QmlDocument *qml = QmlDocument::create("asset:///testing.qml").parent(this);
//	qml->setContextProperty("contactHandler", this);
//
	m_name = "";
	m_pNo = "";
}

Contact::~Contact()
{
}

QString Contact::name()
{
	return m_name;
}

QString Contact::pNo()
{
	return m_pNo;
}

void Contact::test() {
	qDebug() << "Testing";
}

void Contact::contactDetails(QString id)
{

	Contact contact_info = ContactService().contactDetails(id);

//		m_name = contact_info.firstName();
//		QString lastname = contact_info.lastName();
//		QList<ContactAttribute> phoneno_list = contact_info.phoneNumbers();
//
//		QStringList no_s;
//
//
//		foreach(ContactAttribute attr, phoneno_list)
//		{
//		    no_s << attr.value();
//		}
//		m_pNo = no_s[0];
//
//		emit setName(m_name);
//		emit setPhone(m_pNo);
//
//		qdebug() << "Name: " + m_name;
}

 

Please use plain text.
Developer
simon_hain
Posts: 16,113
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: How to get number and name from Contact Picker

did you add the lib to your pro file? did you grant the contact permission?
LIBS += -lbbpim
----------------------------------------------------------
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
Please use plain text.
Developer
jessica99327
Posts: 84
Registered: ‎04-22-2013
My Device: BB 10 Dev
My Carrier: Simulator

Re: How to get number and name from Contact Picker

yes I did.

APP_NAME = testing

CONFIG += qt warn_on debug_and_release cascades

INCLUDEPATH += ../src
SOURCES += ../src/*.cpp
HEADERS += ../src/*.hpp ../src/*.h

LIBS += -lbbcascadespickers -lbbpim -lbbsystem

lupdate_inclusion {
    SOURCES += ../assets/*.qml
}

device {
	CONFIG(release, debug|release) {
		DESTDIR = o.le-v7
		TEMPLATE = lib
        QMAKE_CXXFLAGS_RELEASE += -fvisibility=hidden -mthumb
	}
	CONFIG(debug, debug|release) {
		DESTDIR = o.le-v7-g
	}
}

simulator {
	CONFIG(release, debug|release) {
		DESTDIR = o
	}
	CONFIG(debug, debug|release) {
		DESTDIR = o-g
	}
}

OBJECTS_DIR = $${DESTDIR}/.obj
MOC_DIR = $${DESTDIR}/.moc
RCC_DIR = $${DESTDIR}/.rcc
UI_DIR = $${DESTDIR}/.ui

suredelete.target = sureclean
suredelete.commands = $(DEL_FILE) $${MOC_DIR}/*; $(DEL_FILE) $${RCC_DIR}/*; $(DEL_FILE) $${UI_DIR}/*
suredelete.depends = distclean

QMAKE_EXTRA_TARGETS += suredelete

TRANSLATIONS = \
    $${TARGET}_en_GB.ts \
    $${TARGET}_fr.ts \
    $${TARGET}_it.ts \    
    $${TARGET}_de.ts \
    $${TARGET}_es.ts \
    $${TARGET}.ts

 

    <!-- Request permission to execute native code.  Required for native applications. -->
    <permission system="true">run_native</permission>
    <permission>access_pimdomain_contacts</permission>
    <permission>access_shared</permission>
    <env var="LD_LIBRARY_PATH" value="app/native/lib:/usr/lib/qt4/lib"/>

 

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

Re: How to get number and name from Contact Picker

[ Edited ]

Try adding

using namespace bb::pim::contacts;

after includes. If it still doesn't compile, please paste the exact error message you're seeing in logs.


Andrey Fidrya, @zmeyc on twitter
Please use plain text.
Developer
jessica99327
Posts: 84
Registered: ‎04-22-2013
My Device: BB 10 Dev
My Carrier: Simulator

Re: How to get number and name from Contact Picker

here's the error msg after adding the namespace:

../src/Contact.cpp:8:1: error: reference to 'Contact' is ambiguous
../src/Contact.hpp:7:7: error: candidates are: class Contact
C:/Users/N0189/BB/target_10_1_0_1020/qnx6/usr/include/bb/pim/contacts/Contact.hpp:48:21: error:                 class bb::pim::contacts::Contact
../src/Contact.cpp:8:1: error: 'Contact' does not name a type
../src/Contact.cpp:17:1: error: reference to 'Contact' is ambiguous
../src/Contact.hpp:7:7: error: candidates are: class Contact
C:/Users/N0189/BB/target_10_1_0_1020/qnx6/usr/include/bb/pim/contacts/Contact.hpp:48:21: error:                 class bb::pim::contacts::Contact
../src/Contact.cpp:17:1: error: 'Contact' does not name a type
../src/Contact.cpp:21:9: error: reference to 'Contact' is ambiguous
../src/Contact.hpp:7:7: error: candidates are: class Contact
C:/Users/N0189/BB/target_10_1_0_1020/qnx6/usr/include/bb/pim/contacts/Contact.hpp:48:21: error:                 class bb::pim::contacts::Contact
../src/Contact.cpp:21:9: error: reference to 'Contact' is ambiguous
../src/Contact.hpp:7:7: error: candidates are: class Contact
C:/Users/N0189/BB/target_10_1_0_1020/qnx6/usr/include/bb/pim/contacts/Contact.hpp:48:21: error:                 class bb::pim::contacts::Contact
../src/Contact.cpp: In function 'QString name()':
../src/Contact.cpp:23:9: error: 'm_name' was not declared in this scope
../src/Contact.cpp: At global scope:
../src/Contact.cpp:26:9: error: reference to 'Contact' is ambiguous
../src/Contact.hpp:7:7: error: candidates are: class Contact
C:/Users/N0189/BB/target_10_1_0_1020/qnx6/usr/include/bb/pim/contacts/Contact.hpp:48:21: error:                 class bb::pim::contacts::Contact
../src/Contact.cpp:26:9: error: reference to 'Contact' is ambiguous
../src/Contact.hpp:7:7: error: candidates are: class Contact
C:/Users/N0189/BB/target_10_1_0_1020/qnx6/usr/include/bb/pim/contacts/Contact.hpp:48:21: error:                 class bb::pim::contacts::Contact
../src/Contact.cpp: In function 'QString pNo()':
../src/Contact.cpp:28:9: error: 'm_pNo' was not declared in this scope
../src/Contact.cpp: At global scope:
../src/Contact.cpp:31:6: error: reference to 'Contact' is ambiguous
../src/Contact.hpp:7:7: error: candidates are: class Contact
C:/Users/N0189/BB/target_10_1_0_1020/qnx6/usr/include/bb/pim/contacts/Contact.hpp:48:21: error:                 class bb::pim::contacts::Contact
../src/Contact.cpp:31:6: error: reference to 'Contact' is ambiguous
../src/Contact.hpp:7:7: error: candidates are: class Contact
C:/Users/N0189/BB/target_10_1_0_1020/qnx6/usr/include/bb/pim/contacts/Contact.hpp:48:21: error:                 class bb::pim::contacts::Contact
../src/Contact.cpp:35:6: error: reference to 'Contact' is ambiguous
../src/Contact.hpp:7:7: error: candidates are: class Contact
C:/Users/N0189/BB/target_10_1_0_1020/qnx6/usr/include/bb/pim/contacts/Contact.hpp:48:21: error:                 class bb::pim::contacts::Contact
../src/Contact.cpp:35:6: error: reference to 'Contact' is ambiguous
../src/Contact.hpp:7:7: error: candidates are: class Contact
C:/Users/N0189/BB/target_10_1_0_1020/qnx6/usr/include/bb/pim/contacts/Contact.hpp:48:21: error:                 class bb::pim::contacts::Contact
../src/Contact.cpp: In function 'void contactDetails(QString)':
../src/Contact.cpp:38:2: error: reference to 'Contact' is ambiguous
../src/Contact.hpp:7:7: error: candidates are: class Contact
C:/Users/N0189/BB/target_10_1_0_1020/qnx6/usr/include/bb/pim/contacts/Contact.hpp:48:21: error:                 class bb::pim::contacts::Contact
../src/Contact.cpp:38:10: error: expected ';' before 'contact'
../src/Contact.cpp: At global scope:
../src/Contact.cpp:35:6: warning: unused parameter 'id' [-Wunused-parameter]
../src/Contact.cpp: In function 'QString pNo()':
../src/Contact.cpp:29:1: warning: control reaches end of non-void function [-Wreturn-type]
../src/Contact.cpp: In function 'QString name()':
../src/Contact.cpp:24:1: warning: control reaches end of non-void function [-Wreturn-type]
cc: C:/Users/N0189/BB/host_10_1_0_132/win32/x86/usr/lib/gcc/arm-unknown-nto-qnx8.0.0eabi/4.6.3/cc1plus caught signal 1
make[2]: *** [o.le-v7-g/.obj/Contact.o] Error 1
make[2]: *** Waiting for unfinished jobs....
../src/main.cpp:19:6: warning: unused parameter 'type' [-Wunused-parameter]
make[2]: Leaving directory `C:/Users/N0189/ndk-10.1.0-workspace/HLB/arm'
make[1]: Leaving directory `C:/Users/N0189/ndk-10.1.0-workspace/HLB/arm'
make[1]: *** [debug] Error 2
make: *** [Device-Debug] Error 2

 

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

Re: How to get number and name from Contact Picker

[ Edited ]

Your class is named 'Contact' and it's conflicting with class Contact from bb::smileytongue:im::contacts namespace.

One option is to rename the class, another one is to remove 'using namespace' line and refer to classes using fully-qualified names:

bb::pim::contacts::Contact instead of Contact
bb::pim::contacts::ContactService instead of ContactService

 etc


Andrey Fidrya, @zmeyc on twitter
Please use plain text.