Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. [Solved]Contact Filter returns wrong Info

[Solved]Contact Filter returns wrong Info

Scheduled Pinned Locked Moved Mobile and Embedded
8 Posts 2 Posters 3.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AS.Sri
    wrote on last edited by
    #1

    Hello All,

    The purpose is to add a contact iff the contact doesn't already exists. So i did the following

    @ // Filter for Contact Name search
    //First Name Filter
    QContactDetailFilter firstNameFilter;
    firstNameFilter.setDetailDefinitionName(QContactName::DefinitionName,
    QContactName::FieldFirstName);
    firstNameFilter.setMatchFlags(QContactFilter::MatchCaseSensitive | QContactFilter::MatchContains);
    firstNameFilter.setValue(firstName);

    //Last name Filter
    QContactDetailFilter lastNameFilter;
    lastNameFilter.setDetailDefinitionName(QContactName::DefinitionName,
                                        QContactName::FieldLastName);
    lastNameFilter.setMatchFlags(QContactFilter::MatchCaseSensitive | QContactFilter::MatchContains);
    lastNameFilter.setValue(lastName);
    
    QContactUnionFilter ufil;
    if(middleName.isEmpty())
    {
        ufil.prepend(firstNameFilter);
        ufil.prepend(lastNameFilter);
        //ufil = (firstNameFilter | lastNameFilter);
    }
    else
    {
        //Middle Name Filter
        QContactDetailFilter middleNameFilter;
        middleNameFilter.setDetailDefinitionName(QContactName::DefinitionName,
                                            QContactName::FieldMiddleName);
        middleNameFilter.setMatchFlags(QContactFilter::MatchCaseSensitive | QContactFilter::MatchContains);
        middleNameFilter.setValue(middleName);
    
        ufil.prepend(firstNameFilter);
        ufil.prepend(lastNameFilter);
        ufil.prepend(middleNameFilter);
        //ufil = (firstNameFilter | lastNameFilter | middleNameFilter);
    }
    
    QList<QContact> matchingContacts = m_contactManager->contacts(ufil);@
    

    But it always returns with wrong info. For example if i want to add "ABC(first name) XYZ(last name)" and the contact contains "QWE XYZ" it returns QWE XYZ instead of returning null.

    Could anybody help me with this please.

    1 Reply Last reply
    0
    • C Offline
      C Offline
      chriadam
      wrote on last edited by
      #2

      Hi,

      With what device / environment are you seeing this behaviour?
      There is a bug http://bugreports.qt.nokia.com/browse/QTMOBILITY-856 about something similar on Symbian, but I don't know whether this is the same issue as reported there.

      Cheers,
      Chris.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        AS.Sri
        wrote on last edited by
        #3

        Thanks a lot Chris i commented on the bug report as i am facing the same problem. I tested it on 5230, N97 mini and 5800 (Qt: 4.6.3 and mobility: 1.0.2).

        Is there any workaround? I have no idea about symbian programming.

        1 Reply Last reply
        0
        • C Offline
          C Offline
          chriadam
          wrote on last edited by
          #4

          Well, you can filter manually (by retrieving all contacts, and checking the name fields in a for-loop). But the other possibility is that maybe your usecase is better fulfilled by an intersection filter instead of a union filter, as I believe that intersection filters do not suffer the same problem.

          Eg: create an intersection filter from a first-name-filter and a last-name-filter, then manually compare the contacts returned which match that filter, to the contact which you're searching for.

          Good luck!

          1 Reply Last reply
          0
          • A Offline
            A Offline
            AS.Sri
            wrote on last edited by
            #5

            I replaced QContactUnionFilter with QContactIntersectionFilter and it works now. Thank you.

            What is the difference between these two as functionality looks same? I mean other than Union Vs Intersection difference.

            1 Reply Last reply
            0
            • C Offline
              C Offline
              chriadam
              wrote on last edited by
              #6

              No difference - internally they're just a (sorted) list of filters, thereby allowing arbitrarily complex filter trees. How each filter is handled is backend specific, so backends can perform canonicalisation or logical reduction to improve performance, which is why a bug in the backend can affect the results of a query with a filter.

              In general, for a union filter, the query will return any contact which matches any of the filters in the union; for an intersection filter, the query will return any contact which matches ALL of the filters in the intersection.

              Cheers,
              Chris.

              1 Reply Last reply
              0
              • A Offline
                A Offline
                AS.Sri
                wrote on last edited by
                #7

                Thanks for the explanation Chris it makes much sense now. The Qt Docs for Qt Mobility needs an update :)

                1 Reply Last reply
                0
                • C Offline
                  C Offline
                  chriadam
                  wrote on last edited by
                  #8

                  No worries :-)

                  Please do file bugs on JIRA about any doc issues you see in Mobility, so that the issue can be tracked, prioritised and fixed.

                  Thanks,
                  Chris.

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved