×
Namespaces

Variants
Actions
(Difference between revisions)

Finding contact manager in Qt

From Nokia Developer Wiki
Jump to: navigation, search
tepaa (Talk | contribs)
copyeditor (Talk | contribs)
m
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
 
__NOEDITSECTION__
 
__NOEDITSECTION__
 +
{{KBCS}}
 
{{CodeSnippet
 
{{CodeSnippet
|id=
+
|id=CS001620
 
|platform=S60 5th Edition<br />Maemo 5
 
|platform=S60 5th Edition<br />Maemo 5
 
|devices=Nokia N97, Nokia N900
 
|devices=Nokia N97, Nokia N900
 
|category=Qt
 
|category=Qt
 
|subcategory=Qt Mobility
 
|subcategory=Qt Mobility
|creationdate=May 24, 2010
+
|creationdate=July 7, 2010
 
|keywords= QContactManager, QContactLocalId
 
|keywords= QContactManager, QContactLocalId
 
}}
 
}}
Line 13: Line 14:
 
==Overview==
 
==Overview==
  
This code snippet demonstrates how to search contact back-end managers in Qt using Contacts module of Qt Mobility.  
+
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==
Line 112: Line 113:
 
</code>
 
</code>
  
You can also create QContactManager to stack using "symbian" or "maemo5" backend keys
+
You can also create QContactManager to stack using '''symbian''' or '''maemo5''' backend keys:
 
<code>
 
<code>
 
// Create manager (Symbian backend)
 
// Create manager (Symbian backend)
Line 126: Line 127:
 
==Postconditions==
 
==Postconditions==
  
Contact manager found.
+
Contact manager is found.
  
 
==See also==
 
==See also==

Revision as of 16:24, 7 July 2010


Template:KBCS

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: (07 Jul 2010)
Last edited: copyeditor (07 Jul 2010)

Overview

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

Qt project file

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

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;
};

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");


Postconditions

Contact manager is found.

See also

124 page views in the last 30 days.
×