how to obtain contact list in qt

0 votes
asked Jul 15, 2010 by tirupati-balan

i use this code and getting contact details of only one person ....

contactManager = new QContactManager();
QList<QContact> contacts = contactManager->contacts();
contacts.detail(QContactPhoneNumber::DefinitionName).value(QContactPhoneNumber::FieldNumber);

QContact a = contactManager->contact(contacts.count());
QContactPhoneNumber no = a.detail<QContactPhoneNumber>();
qDebug() << "Name:" << a.displayLabel() << "Number:" << " " << no.number() ;
UserId = a.displayLabel();
PhoneNumber = no.number();

output:

Name: andrew Number: +7811341255

but i want list of contact like this

Name: andrew Number: +7811341255
Name: person2 Number: +44124156
Name: person3 Number: +212113

....list of no of contact in phone any help appreciated....

3 Answers

0 votes
answered Jul 15, 2010 by nubsis

If you want to print all of them, you should iterate over the QList returned by QContactManager::contacts().

This should get you started (I'll just whip it up for you):

// Contacts contains a list of ID:s
QList<QContactLocalId> contacts = contactManager->contacts();

// Now iterate
QList<QContactLocalId>::iterator it;
for (it = contacts.begin(); it != contacts.end(); ++it)
{
  QContact contact = contactManager->contact(*it);
  // And print contact information...
  UserId name = contact.displayLabel();
  PhoneNumber number = contact.number();
  qDebug() << "Name: " << name
           << " Number: " << number << " ";
}

http://doc.qt.nokia.com/qtmobility-1.0-tp/qcontactmanager.html#contacts

http://doc.qt.nokia.com/4.5/qlist.html

http://doc.qt.nokia.com/4.5/qlist-iterator.html

http://www.cppreference.com/wiki/stl/iterators

0 votes
answered Jul 5, 2011 by vinay

Helped me alot...... Thanks...... :)

just a modification it's:

QList<QContactLocalId> contacts = contactManager->contactsIds();

not

QList<QContactLocalId> contacts = contactManager->contacts();
0 votes
answered Sep 15, 2017 by christian-feldbacher

To get a contact list of iOS & Android, you can also use the V-Play SDK for this. There is method nativeUtils.getContacts() which works like this:

import VPlayApps 1.0

App {
  AppListView {
    anchors.fill: parent
    model: nativeUtils.getContacts()

    delegate: SimpleRow {
      text: modelData.name
      detailText: modelData.phoneNumber
    }
  }
}
Welcome to Q&A, where you can ask questions and receive answers from other members of the community.
Website Online Counter

...