×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Registered User
    Join Date
    Jan 2009
    Location
    ભારત->ગુજરાત->ભાવનગર
    Posts
    279

    Post Sorting Contact Alphabetically 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

  2. #2
    Nokia Developer Expert
    Join Date
    Jun 2012
    Posts
    55

    Re: Sorting Contact Alphabetically in ListWidget

    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.

    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);
    Br,
    Villep

  3. #3
    Registered User
    Join Date
    Jan 2009
    Location
    ભારત->ગુજરાત->ભાવનગર
    Posts
    279

    Re: Sorting Contact Alphabetically in ListWidget

    Still i didn't get this line
    Code:
    sort.setDetailDefinitionName(QContactName::DefinitionName, QContactName::FieldLastName);
    "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"

    Actually i am not getting the meaning of the above statement for mentioned function.
    Regards
    Viral Parmar

  4. #4
    Nokia Developer Expert
    Join Date
    Jun 2012
    Posts
    55

    Re: Sorting Contact Alphabetically in ListWidget

    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.

  5. #5
    Registered User
    Join Date
    Jan 2009
    Location
    ભારત->ગુજરાત->ભાવનગર
    Posts
    279

    Re: Sorting Contact Alphabetically in ListWidget

    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

  6. #6
    Nokia Developer Expert
    Join Date
    Jun 2012
    Posts
    55

    Re: Sorting Contact Alphabetically in ListWidget

    Yes, for each contact you should create a new QListWidgetItem and add it to the listwidget.

    Br,
    Villep

Similar Threads

  1. sorting list items alphabetically
    By Nourayn in forum Symbian User Interface
    Replies: 4
    Last Post: 2009-01-22, 07:50
  2. sort RMS records alphabetically?
    By artemg in forum Mobile Java General
    Replies: 2
    Last Post: 2004-02-03, 14:38

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •