[Solved]Contact Filter returns wrong Info
-
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.
-
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. -
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!
-
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.