×
Namespaces

Variants
Actions
(Difference between revisions)

Finding contact manager in Qt

From Nokia Developer Wiki
Jump to: navigation, search
tepaa (Talk | contribs)
jimgilmour1 (Talk | contribs)
m (minor format)
Line 13: Line 13:
 
==Overview==
 
==Overview==
  
This code snippet demonstrates how to search contact backend managers in Qt using Contacts module of Qt Mobility.  
+
This code snippet demonstrates how to search contact back-end managers in Qt using Contacts module of Qt Mobility.  
  
 
==Qt project file==
 
==Qt project file==
Line 76: Line 76:
 
void qtSnippets::createManager()
 
void qtSnippets::createManager()
 
{
 
{
     // Get list of different contact backends
+
     // Get list of different contact back-ends
 
     QStringList availableManagers = QContactManager::availableManagers();
 
     QStringList availableManagers = QContactManager::availableManagers();
  
 
     QList<QContactLocalId> contactIds;
 
     QList<QContactLocalId> contactIds;
     // Try to find contacts from some backend
+
     // Try to find contacts from some back-end
 
     while (!availableManagers.isEmpty()) {
 
     while (!availableManagers.isEmpty()) {
 
         // Get some manager
 
         // Get some manager
Line 100: Line 100:
 
     }
 
     }
  
     // Use default if no contact found from any backend
+
     // Use default if no contact found from any back-end
 
     if (!m_contactManager) {
 
     if (!m_contactManager) {
 
         m_contactManager = new QContactManager();
 
         m_contactManager = new QContactManager();

Revision as of 13:04, 24 May 2010


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: (24 May 2010)
Last edited: jimgilmour1 (24 May 2010)

Overview

This code snippet demonstrates how to search contact back-end 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 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);
}

Postconditions

Contact manager found.

See also

120 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.

×