×
Namespaces

Variants
Actions
(Difference between revisions)

Finding contact manager in Qt

From Nokia Developer Wiki
Jump to: navigation, search
tepaa (Talk | contribs)
(Created page with '__NOTOC__ __NOEDITSECTION__ {{CodeSnippet |id= |platform=S60 5th Edition<br />Maemo 5 |devices=Nokia N97, Nokia N900 |category=Qt |subcategory=Qt Mobility |creationdate=May 24, 2…')
 
tepaa (Talk | contribs)
Line 119: Line 119:
 
* [[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
* http://developer.symbian.org/wiki/index.php/Complete_Guide_To_Symbian_Signed
 
* https://www.symbiansigned.com/app/page/public/openSignedOnline.do
 
  
 
[[Category:Qt]][[Category:Qt Mobility]][[Category:Code Examples]][[Category:Code Snippet]]
 
[[Category:Qt]][[Category:Qt Mobility]][[Category:Code Examples]][[Category:Code Snippet]]

Revision as of 10:23, 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: 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.

See also

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

×