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:20, 17 October 2012 by hamishwillee (Talk | contribs)

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

Receiving an SMS in Qt

From Wiki
Jump to: navigation, search

This code snippet demonstrates how to listen for incoming SMS messages in Qt. The snippet uses the Qt Mobility Messaging module to show the received message to the user and then to remove it from the inbox folder.

Article Metadata
Tested with
SDK: Qt Mobility 1.0.0
Devices(s): Nokia N97, Nokia N900
Platform(s): S60 5th Edition
Maemo 5
S60 5th Edition
Platform Security
Signing Required: DevCert
Capabilities: ReadUserData WriteUserData ReadDeviceData WriteDeviceData
Keywords: QMessage, QMessageAddress, QMessageAccountId, QMessageService
Created: tepaa (21 May 2010)
Last edited: hamishwillee (17 Oct 2012)


Qt project file

Link the Messaging Qt Mobility module into 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 {
WriteUserData \
ReadDeviceData \


#include <QMainWindow>
#include <QPointer>
#include <QMessageBox>
#include <qmessage.h>
#include <qmessagemanager.h>
// QtMobility namespace
class qtSnippets : public QMainWindow
qtSnippets(QWidget *parent = 0);
private slots:
void processIncomingSMS();
// Listening signals from QMessageManager
void messageAdded(const QMessageId&,
const QMessageManager::NotificationFilterIdSet&);
QPointer<QMessageManager> m_manager;
QMessageManager::NotificationFilterIdSet m_notifFilterSet;
QMessageId m_messageId;


#include <QTimer>
qtSnippets::qtSnippets(QWidget *parent)
: QMainWindow(parent)
// Manager for listening messages
m_manager = new QMessageManager(this);
// Listen new added messages
connect(m_manager, SIGNAL(messageAdded(const QMessageId&,
const QMessageManager::NotificationFilterIdSet&)),
this, SLOT(messageAdded(const QMessageId&,
const QMessageManager::NotificationFilterIdSet&)));
// Create 2 filers set for filtering messages
// - SMS filter
// - InboxFolder filter
QMessageFilter::byType(QMessage::Sms) &
void qtSnippets::messageAdded(const QMessageId& id,
const QMessageManager::NotificationFilterIdSet& matchingFilterIds)
// Message added...
if (matchingFilterIds.contains(m_notifFilterSet)) {
// ...and it fits into our filters, lets process it
m_messageId = id;
QTimer::singleShot(0, this, SLOT(processIncomingSMS()));
void qtSnippets::processIncomingSMS()
QMessage message = m_manager->message(m_messageId);
// SMS message body
QString messageString = message.textContent();
// Show message to user
QMessageBox::information(this, "Incoming SMS", messageString);
// Remove message from inbox


An SMS message has been received and shown to the user, and then removed from the inbox folder.

See also

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