Creating contact in Qt

From Qt Wiki
Jump to navigation Jump to search

Template:Abstract

Template:ArticleMetaData

Qt project file[edit | edit source]

CONFIG += mobility MOBILITY = contacts

symbian { TARGET.CAPABILITY = ReadUserData WriteUserData }

Header[edit | edit source]

// QtMobility

  1. include <qcontactmanager.h>
  2. include <qcontact.h>
  3. include <qcontactdetailfilter.h>
  4. include <qcontactphonenumber.h>
  5. include <qcontactname.h>

QTM_USE_NAMESPACE

Source[edit | edit source]

// Create manager (Symbian backend) QContactManager contactManager("symbian");

// Create a new empty contact QContact contact;

// Set firstname and lastname QContactName name; name.setFirstName("Steven"); name.setLastName("Segal"); contact.saveDetail(&name);

// Set number QContactPhoneNumber number; number.setNumber("1234567890"); contact.saveDetail(&number);

// Save the contact if (!contactManager.saveContact(&contact)) {

   QMessageBox::information(this, "Failed!", 
   QString("Failed to save contact!\n(error code %1)").arg(contactManager.error()));

}

Postconditions[edit | edit source]

A new contact is created.

See also[edit | edit source]