QContactManager详解
hamishwillee
(Talk | contribs) m (Hamishwillee - Automated change of category from Lang-CN to Unlikely Category) |
hamishwillee
(Talk | contribs) m (Text replace - "<code cpp>" to "<code cpp-qt>") |
||
| (4 intermediate revisions by one user not shown) | |||
| Line 1: | Line 1: | ||
| + | {{ArticleMetaData | ||
| + | |sourcecode=[[Media:Wrtwrapper.zip]] [[Media:Samplephonebook.zip]] | ||
| + | |installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) --> | ||
| + | |devices= <!-- Devices tested against - e.g. ''devices=Nokia 6131 NFC, Nokia C7-00'') --> | ||
| + | |sdk= <!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Nokia Qt SDK 1.1]) --> | ||
| + | |platform= <!-- Compatible platforms - e.g. Symbian^1 and later, Qt 4.6 and later --> | ||
| + | |devicecompatability= <!-- Compatible devices e.g.: All* (must have internal GPS) --> | ||
| + | |dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 --> | ||
| + | |signing=<!-- Signing requirements - empty or one of: Self-Signed, DevCert, Manufacturer --> | ||
| + | |capabilities= <!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. --> | ||
| + | |keywords= <!-- APIs, classes and methods (e.g. QSystemScreenSaver, QList, CBase --> | ||
| + | |id= <!-- Article Id (Knowledge base articles only) --> | ||
| + | |language=Lang-Chinese | ||
| + | |translated-by= <!-- [[User:XXXX]] --> | ||
| + | |translated-from-title= <!-- Title only --> | ||
| + | |translated-from-id= <!-- Id of translated revision --> | ||
| + | |review-by=<!-- After re-review: [[User:username]] --> | ||
| + | |review-timestamp= <!-- After re-review: YYYYMMDD --> | ||
| + | |update-by= <!-- After significant update: [[User:username]]--> | ||
| + | |update-timestamp= <!-- After significant update: YYYYMMDD --> | ||
| + | |creationdate=20110109 | ||
| + | |author=[[User:Max.chen]] | ||
| + | }} | ||
| + | |||
[[Category:Qt Mobility]] | [[Category:Qt Mobility]] | ||
QContactManager提供了访问和联系人相关信息的接口。 | QContactManager提供了访问和联系人相关信息的接口。 | ||
| Line 5: | Line 29: | ||
对于大多数用户来说,他们仅仅是想获取系统联系人的一些相关信息,那么系统缺省的QContactManager就足以满足他们的要求了。构造缺省的QContactManager非常简单,代码如下: | 对于大多数用户来说,他们仅仅是想获取系统联系人的一些相关信息,那么系统缺省的QContactManager就足以满足他们的要求了。构造缺省的QContactManager非常简单,代码如下: | ||
| − | <code cpp> | + | <code cpp-qt> |
QContactManager cm; // instantiate the default manager | QContactManager cm; // instantiate the default manager | ||
</code> | </code> | ||
| Line 16: | Line 40: | ||
在例子 QWhoWhere 中就是采用的这种方式: | 在例子 QWhoWhere 中就是采用的这种方式: | ||
| − | <code cpp> | + | <code cpp-qt> |
void MainWindow::createContactManager() | void MainWindow::createContactManager() | ||
{ | { | ||
| Line 33: | Line 57: | ||
=== 获得全部QContactManager列表 === | === 获得全部QContactManager列表 === | ||
通过QContactManager的静态方法availableManagers (): | 通过QContactManager的静态方法availableManagers (): | ||
| − | <code cpp> | + | <code cpp-qt> |
QStringList QContactManager::availableManagers () [static] | QStringList QContactManager::availableManagers () [static] | ||
</code> | </code> | ||
可以返回当前系统中所有支持的ContactManager。让后可以通过上面提到的方法构造QContactManager的实例。或者通过静态方法: | 可以返回当前系统中所有支持的ContactManager。让后可以通过上面提到的方法构造QContactManager的实例。或者通过静态方法: | ||
| − | <code cpp> | + | <code cpp-qt> |
QContactManager * QContactManager::fromUri ( const QString & managerUri, QObject * parent = 0 ) [static] | QContactManager * QContactManager::fromUri ( const QString & managerUri, QObject * parent = 0 ) [static] | ||
</code> | </code> | ||
| Line 46: | Line 70: | ||
=== QContactManager的使用 === | === QContactManager的使用 === | ||
我们无论使用何种发放获得了QContactManager 的实例,都是为了对联系人进行操作。QContactManager 提供了一组方法对联系人进行增删改查的操作。下面这段代码演示了如何查询联系人的方法: | 我们无论使用何种发放获得了QContactManager 的实例,都是为了对联系人进行操作。QContactManager 提供了一组方法对联系人进行增删改查的操作。下面这段代码演示了如何查询联系人的方法: | ||
| − | <code cpp> | + | <code cpp-qt> |
QString ContactServer::getContacts() | QString ContactServer::getContacts() | ||
{ | { | ||
| Line 67: | Line 91: | ||
另外,QContactManager 还提供了一组方法,用来查询一个QContactManager 实例是否具备某些能力或功能,例如: | 另外,QContactManager 还提供了一组方法,用来查询一个QContactManager 实例是否具备某些能力或功能,例如: | ||
| − | <code cpp> | + | <code cpp-qt> |
QContactManager cm; | QContactManager cm; | ||
qDebug() << "The default manager for the platform is:" << cm.managerName(); | qDebug() << "The default manager for the platform is:" << cm.managerName(); | ||
| Line 75: | Line 99: | ||
</code> | </code> | ||
| − | [[Category:Lang-Chinese]] | + | [[Category:Lang-Chinese]][[Category:MeeGo Harmattan]] [[Category:Symbian]] |
Latest revision as of 04:23, 11 October 2012
文章信息
QContactManager提供了访问和联系人相关信息的接口。
Contents |
获得缺省的QContactManager
对于大多数用户来说,他们仅仅是想获取系统联系人的一些相关信息,那么系统缺省的QContactManager就足以满足他们的要求了。构造缺省的QContactManager非常简单,代码如下:
QContactManager cm; // instantiate the default manager
在文章通过Qt Mobility扩展JavaScript功能中的File:Wrtwrapper.zip就是使用这种方法构造的。
获得特定的QContactManager
当用户需要时,可以通过参数来获得特定的QContactManager。
在例子 QWhoWhere 中就是采用的这种方式:
void MainWindow::createContactManager()
{
if (!m_contactManager) {
#if defined Q_WS_HILDON || defined Q_WS_MAEMO_5
m_contactManager = new QContactManager("maemo5");
#elif defined Q_OS_SYMBIAN
m_contactManager = new QContactManager("symbian");
#endif
}
}
在 这里 可以找到QWhoWhere 的相关信息和源代码。
获得全部QContactManager列表
通过QContactManager的静态方法availableManagers ():
QStringList QContactManager::availableManagers () [static]
可以返回当前系统中所有支持的ContactManager。让后可以通过上面提到的方法构造QContactManager的实例。或者通过静态方法:
来获取QContactManager对象的一个实例。
在Qt Mobility附带的例子samplephonebookFile:Samplephonebook.zip中使用的就是这种方法。
QContactManager的使用
我们无论使用何种发放获得了QContactManager 的实例,都是为了对联系人进行操作。QContactManager 提供了一组方法对联系人进行增删改查的操作。下面这段代码演示了如何查询联系人的方法:
QString ContactServer::getContacts()
{
QContactManager cm; // instantiate the default manager
QList<QContact> allContacts = cm.contacts();
QString temp ="";
for (int i = 0; i < allContacts.size() && i<5 ; ++i) {
QContact aContact = allContacts.at(i) ;
temp += "Last name:" +aContact.detail<QContactName>().lastName ()+"<br>" +
"First name:" + aContact.detail<QContactName>().firstName () + "<br>";
}
return temp;
}
另外,QContactManager 还提供了一组方法,用来查询一个QContactManager 实例是否具备某些能力或功能,例如:
QContactManager cm;
qDebug() << "The default manager for the platform is:" << cm.managerName();
qDebug() << "It" << (cm.isRelationshipTypeSupported(QContactRelationship::HasAssistant) ? "supports" : "does not support") << "assistant relationships.";
qDebug() << "It" << (cm.supportedContactTypes().contains(QContactType::TypeGroup) ? "supports" : "does not support") << "groups.";
qDebug() << "It" << (cm.hasFeature(QContactManager::MutableDefinitions) ? "supports" : "does not support") << "mutable detail definitions.";

