Finding contact manager in Qt
| Line 23: | Line 23: | ||
<code cpp> | <code cpp> | ||
| − | symbian | + | symbian { |
TARGET.CAPABILITY = ReadUserData WriteUserData | TARGET.CAPABILITY = ReadUserData WriteUserData | ||
} | } | ||
Revision as of 10:24, 24 May 2010
Article Metadata
Tested with
Devices(s): Nokia N97, Nokia N900
Compatibility
Platform(s): S60 5th Edition
Maemo 5
Maemo 5
Article
Keywords: QContactManager, QContactLocalId
Created: (24 May 2010)
Last edited: tepaa
(24 May 2010)
Overview
This code snippet demonstrates how to search contact backend managers in Qt using 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 the
// create manager
QTimer::singleShot(0, this, SLOT(createManager()));
}
qtSnippets::~qtSnippets()
{
delete m_contactManager;
}
void qtSnippets::createManager()
{
// Get list of different contact backends
QStringList availableManagers = QContactManager::availableManagers();
QList<QContactLocalId> contactIds;
// Try to find contacts from some backend
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 backend
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);
}
Postconditions
Contact manager found.

