×
Namespaces

Variants
Actions
(Difference between revisions)

Finding contact manager in Qt

From Nokia Developer Wiki
Jump to: navigation, search
copyeditor (Talk | contribs)
m
hamishwillee (Talk | contribs)
m (Hamishwillee - Add Abstract. Improve categories)
 
(9 intermediate revisions by 2 users not shown)
Line 1: Line 1:
__NOTOC__
+
[[Category:Qt]][[Category:Qt Mobility]][[Category:MeeGo Harmattan]][[Category:Symbian]][[Category:PIM]][[Category:Code Snippet]][[Category:S60 5th Edition]]
__NOEDITSECTION__
+
{{Abstract|This code snippet demonstrates how to search contact back-end managers in Qt using the Qt Mobility Contacts module.}}
{{KBCS}}
+
 
{{CodeSnippet
+
{{ArticleMetaData <!-- v1.2 -->
|id=CS001620
+
|sourcecode= <!-- Link to example source code (e.g. [[Media:The Code Example ZIP.zip]]) -->
|platform=S60 5th Edition<br />Maemo 5
+
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
|devices=Nokia N97, Nokia N900
+
|devices= Nokia N97, Nokia N900
|category=Qt
+
|sdk= <!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Nokia Qt SDK 1.1]) -->
|subcategory=Qt Mobility
+
|platform= S60 5th Edition<br />Maemo 5
|creationdate=July 7, 2010
+
|devicecompatability= <!-- Compatible devices (e.g.: All* (must have GPS) ) -->
 +
|dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 -->
 +
|signing= <!-- Empty or one of Self-Signed, DevCert, Manufacturer -->
 +
|capabilities= <!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. -->
 
|keywords= QContactManager, QContactLocalId
 
|keywords= QContactManager, QContactLocalId
 +
|language= <!-- Language category code for non-English topics - e.g. 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= 20100524
 +
|author= [[User:Tepaa]]
 +
<!-- The following are not in current metadata -->
 +
|id= CS001620
 
}}
 
}}
 
==Overview==
 
 
This code snippet demonstrates how to search contact back-end managers in Qt using the Contacts module of Qt Mobility.
 
  
 
==Qt project file==
 
==Qt project file==
  
<code cpp>
+
<code cpp-qt>
 
CONFIG += mobility
 
CONFIG += mobility
 
MOBILITY = contacts
 
MOBILITY = contacts
 
</code>
 
</code>
  
<code cpp>
+
<code cpp-qt>
 
symbian {
 
symbian {
 
TARGET.CAPABILITY = ReadUserData WriteUserData
 
TARGET.CAPABILITY = ReadUserData WriteUserData
Line 31: Line 42:
 
==Header==
 
==Header==
  
<code cpp>
+
<code cpp-qt>
 
#include <QtGui/QMainWindow>
 
#include <QtGui/QMainWindow>
 
#include <QPointer>
 
#include <QPointer>
Line 58: Line 69:
 
==Source==
 
==Source==
  
<code cpp>
+
<code cpp-qt>
 
#include <QTimer>
 
#include <QTimer>
 
#include <QMessageBox>
 
#include <QMessageBox>
Line 130: Line 141:
  
 
==See also==
 
==See also==
* [[Setting_up_Qt_Mobility]]
+
* [[Setting up Qt Mobility]]
 
* http://doc.qt.nokia.com/qtmobility-1.0/contacts.html
 
* http://doc.qt.nokia.com/qtmobility-1.0/contacts.html
 
[[Category:Qt]][[Category:Qt Mobility]][[Category:Code Examples]][[Category:Code Snippet]]
 

Latest revision as of 09:32, 17 October 2012

This code snippet demonstrates how to search contact back-end managers in Qt using the Qt Mobility Contacts module.

Article Metadata
Tested with
Devices(s): Nokia N97, Nokia N900
Compatibility
Platform(s): S60 5th Edition
Maemo 5
Symbian
S60 5th Edition
Article
Keywords: QContactManager, QContactLocalId
Created: tepaa (24 May 2010)
Last edited: hamishwillee (17 Oct 2012)

Contents

[edit] Qt project file

CONFIG += mobility
MOBILITY = contacts
symbian {
TARGET.CAPABILITY = ReadUserData WriteUserData
}

[edit] Header

#include <QtGui/QMainWindow>
#include <QPointer>
 
// QtMobility
#include <qcontactmanager.h>
#include <qcontact.h>
QTM_USE_NAMESPACE
 
class qtSnippets : public QMainWindow
{
Q_OBJECT
 
public:
qtSnippets(QWidget *parent = 0);
~qtSnippets();
 
private slots:
void createManager();
 
private:
QPointer<QContactManager> m_contactManager;
};

[edit] Source

#include <QTimer>
#include <QMessageBox>
 
qtSnippets::qtSnippets(QWidget *parent)
: QMainWindow(parent)
{
// Let application to startup fully and then
// create manager
QTimer::singleShot(0, this, SLOT(createManager()));
}
 
qtSnippets::~qtSnippets()
{
delete m_contactManager;
}
 
void qtSnippets::createManager()
{
// Get list of different contact back-ends
QStringList availableManagers = QContactManager::availableManagers();
 
QList<QContactLocalId> contactIds;
// Try to find contacts from some back-end
while (!availableManagers.isEmpty()) {
// Get some manager
m_contactManager = new QContactManager(availableManagers.first());
availableManagers.removeFirst();
 
// Contacts exists?
contactIds = m_contactManager->contactIds();
if (!contactIds.isEmpty()) {
// Contact found
availableManagers.clear();
break;
}
else {
// Not found, try the next manager
delete m_contactManager;
m_contactManager = 0;
}
}
 
// Use default if no contact found from any back-end
if (!m_contactManager) {
m_contactManager = new QContactManager();
}
 
// Show message to the user
QString msg = QString("Manager %1 created, that has %2 contacts")
.arg(m_contactManager->managerName()).arg(contactIds.count());
QMessageBox::information(this,"Contacts",msg);
}

You can also create QContactManager to stack using symbian or maemo5 backend keys:

// Create manager (Symbian backend)
QContactManager contactManager("symbian");
// Create manager (Maemo 5, Nokia N900 backend)
QContactManager contactManager("maemo5");


[edit] Postconditions

Contact manager is found.

[edit] See also

This page was last modified on 17 October 2012, at 09:32.
124 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×