Finding contact manager in Qt
hamishwillee
(Talk | contribs) m (Text replace - "<code cpp>" to "<code cpp-qt>") |
hamishwillee
(Talk | contribs) m (Hamishwillee - Add Abstract. Improve categories) |
||
| Line 1: | Line 1: | ||
| + | [[Category:Qt]][[Category:Qt Mobility]][[Category:MeeGo Harmattan]][[Category:Symbian]][[Category:PIM]][[Category:Code Snippet]][[Category:S60 5th Edition]] | ||
| + | {{Abstract|This code snippet demonstrates how to search contact back-end managers in Qt using the Qt Mobility Contacts module.}} | ||
| + | |||
{{ArticleMetaData <!-- v1.2 --> | {{ArticleMetaData <!-- v1.2 --> | ||
|sourcecode= <!-- Link to example source code (e.g. [[Media:The Code Example ZIP.zip]]) --> | |sourcecode= <!-- Link to example source code (e.g. [[Media:The Code Example ZIP.zip]]) --> | ||
| Line 21: | Line 24: | ||
|author= [[User:Tepaa]] | |author= [[User:Tepaa]] | ||
<!-- The following are not in current metadata --> | <!-- The following are not in current metadata --> | ||
| − | |||
|id= CS001620 | |id= CS001620 | ||
}} | }} | ||
| − | |||
| − | |||
| − | |||
| − | |||
==Qt project file== | ==Qt project file== | ||
| Line 145: | Line 143: | ||
* [[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 | ||
| − | |||
| − | |||
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
Maemo 5
Article
Keywords: QContactManager, QContactLocalId
Created: tepaa
(24 May 2010)
Last edited: hamishwillee
(17 Oct 2012)
Contents |
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.

