Hi Eric,
Mardi, le 26 juillet 2011, à 17:26, Eric Lapuyade a écrit:
> Hi,
>
> I can't seem to be able to save a modified contact in the simulator.
Sorry, just reading, do not have a simulator running. So cannot try to
reproduce anything. Still:
> Here is the code:
>
> QContactManager contactMgr;// this instantiates the memory contact
> manager
Are you sure here about the memory contact manager as default one?
Can you tell what contactMgr.managerUri() returns as string?
> QList list = contactMgr.contacts();
> QContact *contact = list[0];
Hm, did this compile? IMNSHO this needs to be:
QContact contact = list[0];
or, if are okay with modifying the first element of the list
QContact &contact = list[0];
> QContactFavorite favorite = contact->detail();
>
> qDebug("%s Favorite set to %d",
> contact->displayLabel().toAscii().data(), favorite.isFavorite());
> --> all favorites are always zero after simulator startup
Who stored the contacts? And have any favorite details been stored before?
Because by default a QContact does not have a QContactFavorite detail. So
contact.detail()
will just return a default QContactFavorite().
Test the returned detail with .isEmpty() to see yourself.
With an empty detail any fields will have the same value as converting a
QVariant() to the field type will have.
> // invert favorite detail and save it back into the contact
> favorite.setFavorite(!favorite.isFavorite());
> contactP->saveDetail(&favorite);
>
> // save the contact back into the store
> bool result = contactMgr.saveContact (contactP);
> --> this returns true, which means success
>
> // now, reload all contacts from the manager
> QList list2 = contactMgr.contacts();
>
> // At this point, if I fetch the same contact again that I just saved, I
> see it was not modified.
> QContact *contact2 = list2[0];
>
> Any idea what I'm doing wrong? or maybe it's a normal behavior when
> using the memory contact manager ?
Besides the strange QContact pointer you use in your code, the rest looks like
it should be, I think. Unless the QContactFavorite is not part of the backend
data schema. Check the result of
contactMgr.detailDefinition(QContactFavorite::DefinitionName,QContactType::TypeContact);
But then "result" of the save should not have been true (with a correctly
working backend).
Unrelated, but still worthwhile: once turning to use other backends then the
memory one, you should switch to use the async api of QContactManager, with
the request objects, as the sync calls can be blocking for quite some time.
Cheers
Friedrich
--
Desktop Summit 2011 in Berlin - Registered already? - www.desktopsummit.org
___
MeeGo-dev mailing list
MeeGo-dev@meego.com
http://lists.meego.com/listinfo/meego-dev
http://wiki.meego.com/Mailing_list_guidelines