Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Revision as of 06:30, 17 October 2012 by hamishwillee (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Requesting an SMS from the inbox folder in Qt

From Wiki
Jump to: navigation, search

This code snippet demonstrates how to request SMS messages from the device's inbox folder in Qt, using the Qt Mobility Messaging module.

Article Metadata
Tested with
Devices(s): Nokia N97, Nokia N900
Compatibility
Platform(s): S60 5th Edition
Maemo 5
Symbian
Article
Keywords: QMessageService, QMessageManager, QMessage, QMessageId
Created: tepaa (21 May 2010)
Last edited: hamishwillee (17 Oct 2012)

Contents

Qt project file

Link the Messaging Qt Mobility module to the project.

CONFIG += mobility
MOBILITY = messaging

Using Messaging requires the ReadDeviceData and WriteDeviceData capabilities from Open Signed Online. For more information, see the User guide: Symbian Signed.

symbian {
TARGET.CAPABILITY = ReadUserData \
WriteUserData \
ReadDeviceData \
WriteDeviceData
}

Header

#include <QtGui/QMainWindow>
#include <QPointer>
#include <QMessageBox>
 
// QtMobility
#include <qmessage.h>
#include <qmessageservice.h>
#include <qmessagemanager.h>
QTM_USE_NAMESPACE
 
class qtSnippets : public QMainWindow
{
Q_OBJECT
 
public:
qtSnippets(QWidget *parent = 0);
~qtSnippets();
 
// Execute query using filters
void queryMessages();
 
public slots:
// Listens messagesFound() signal of QMessageService
void messagesFound(const QMessageIdList&);
 
private:
QPointer<QMessageService> m_service;
QPointer<QMessageManager> m_manager;
};

Source

qtSnippets::qtSnippets(QWidget *parent)
: QMainWindow(parent)
{
// QMessageService class provides the interface
// for requesting messaging service operations
m_service = new QMessageService(this);
QObject::connect(m_service,
SIGNAL(messagesFound(const QMessageIdList&)),
this,
SLOT(messagesFound(const QMessageIdList&)));
 
// QMessageManager class represents the main interface for storage and
// retrieval of messages, folders and accounts in the system message store
m_manager = new QMessageManager(this);
 
// Query messages
queryMessages();
}
 
qtSnippets::~qtSnippets()
{
}
 
void qtSnippets::queryMessages()
{
// Create filers for query, we query SMS messages
// that exists in the inbox folder
QMessageFilter queryFilter(QMessageFilter::byType(QMessage::Sms) &
QMessageFilter::byStandardFolder(QMessage::InboxFolder));
 
m_service->queryMessages(queryFilter);
// NOTE: qtSnippets::messagesFound() is called if messages found
}
 
void qtSnippets::messagesFound(const QMessageIdList &ids)
{
foreach(const QMessageId& id, ids)
{
// Get QMessage
QMessage message = m_manager->message(id);
// Get message string
QString messageString = message.textContent();
// Show to user
QMessageBox::information(this,"Incoming SMS",messageString);
}
}

Postconditions

Existing SMS messages found in the inbox folder.

See also

This page was last modified on 17 October 2012, at 06:30.
46 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.

×