开发者

how to obtain contact list in qt

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:" &开发者_运维百科lt;< " " << 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....


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


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

just a modification it's:

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

not

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


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
    }
  }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜