I am successfully able to retrieve all the contact on my phone , but they are displayed randomly .
I wanted them to be sorted alphabetically and then displayed in listwidget..
I am successfully able to retrieve all the contact on my phone , but they are displayed randomly .
I wanted them to be sorted alphabetically and then displayed in listwidget..
Regards
Viral Parmar
Assuming you are using the code from your other post. QContactManager has a function contactIds which can take parameter containing a list of QContactSortOrder to sort contacts accordingly.
Br,Code:// Sort contacts by lastname QContactSortOrder sort; sort.setDirection(Qt::AscendingOrder); sort.setDetailDefinitionName(QContactName::DefinitionName, QContactName::FieldLastName); QList<QContactSortOrder> sorters; sorters << sort; QList<QContactLocalId> contacts = contactManager->contactIds(sorters);
Villep
Still i didn't get this line
"Sets the definition name of the details which will be inspected to perform sorting to definitionName, and the name of those details' fields which contains the value which contacts will be sorted by to fieldName"Code:sort.setDetailDefinitionName(QContactName::DefinitionName, QContactName::FieldLastName);
Actually i am not getting the meaning of the above statement for mentioned function.
Regards
Viral Parmar
setDetailDefinitionName takes two parameters.
First one is basically a unique identifier that contains semantics and structure of the detail(look here and here for more information).
DefinitionName is a static variable which contains the above infromation for QContactName.
Second parameter contains the name of the field to sort by, in this case FieldLastName.
Here is an example of a custom contactdetail. In the example case QContactPhoneNumber::FieldNumber would return "PhoneNumber".
Hope this helps.
Br,
Villep
Last edited by Villep; 2012-07-30 at 12:45.
Thanks ....got it..
Is it appropriate to create a new object for QListWidgetItem every time iterating over Contactids as shown in code below??
Code:foreach (const QContactLocalId& id, contacts) { QListWidgetItem *currItem = new QListWidgetItem; currContact = cm->contact(id); QContactDisplayLabel dl = currContact.detail(QContactDisplayLabel::DefinitionName); currItem->setData(Qt::DisplayRole, dl.label()); currItem->setData(Qt::UserRole, currContact.localId()); // also store the id of the contact ui->listWidget_2->addItem(currItem); }
Regards
Viral Parmar
Yes, for each contact you should create a new QListWidgetItem and add it to the listwidget.
Br,
Villep