Namespaces
Variants
Actions

Send SMS using Qt Mobility

Jump to: navigation, search
Article Metadata

Tested with
Devices(s): Nokia N97 Mini, Nokia N900

Compatibility
Platform(s): S60 5th Edition, Maemo 5

Platform Security
Signing Required: DevCert required
Capabilities: ReadUserData, WriteUserData, ReadDeviceData, WriteDeviceData

Article
Keywords: QMessageServiceAction, QMessageId
Created: skumar_rao (07 Jul 2010)
Last edited: hamishwillee (11 May 2012)
Warning.png
Warning: This example is outdated and may not compile with new sdks; see this for new examples Qt Mobility API Basic Examples Part 1
Tip.png
Tip: Read this article before moving forward: Setting up environment for Qt Mobility API

Contents

Overview

The following code shows how to send an SMS using Qt Mobility.

Keywords

Project configuration file (.Pro file)

  • Add the Qt Mobility project configuration option in the .Pro file as shown below
CONFIG += mobility
MOBILITY += messaging

The use of Messaging requires the ReadUserData and WriteUserData capabilities from the user granted category. It also requires the ReadDeviceData and WriteDeviceData capabilities from the open signed online category. Read more about Capabilities.

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

Headers

#include <qtmessaging.h>
 
private slots:
void messageStateChanged(QMessageServiceAction::State s);
private:
QMessageServiceAction m_MessageServiceAction;
QMessageId m_sendId;

Source file

// connect messages state-change signal to our slot, to get notification    
connect(&m_MessageServiceAction, SIGNAL(stateChanged(QMessageServiceAction::State)), this, SLOT(messageStateChanged(QMessageServiceAction::State)));
 
void send_sms::QtSendSMSMessage(QString address, QString body) {
// Prepare QMessage with address & body
QMessage message;
message.setType(QMessage::Sms);
message.setTo(QMessageAddress(address, QMessageAddress::Phone));
message.setBody(body);
 
if (iMessageServiceAction.send(message)) {
sendId = message.id();
}
else {
// message sending failed
}
}
 
void send_sms::messageStateChanged(QMessageServiceAction::State s) {
if (s == QMessageServiceAction::Successful) {
// message send successful
}
else {
// message sending failed
}
}

Classes

Reference links

Comments

Hello,

This code is only appropriate for 1.0-tp. The QMessageServiceAction class is not in 1.0 and higher. Consider

int main(int argc, char** argv)
{
   QCoreApplication consoleApplication(argc,argv);
   QMessage testMessage;
   testMessage.setType(QMessage::Sms);
   testMessage.setParentAccountId(QMessageAccount::defaultAccount(QMessage::Sms));
   testMessage.setTo(QMessageAddress(QMessageAddress::Phone,"1234567890"));
   testMessage.setBody("Hello there from test program");
   QMessageService testService;
   bool result = testService.send(testMessage);
   std::cout << "Send message result " << (result ? "Ok" : "Failed") << std::endl;
   return result ? 0 : 1;
}  

an example from qt mobility bug 64 http://bugreports.qt.nokia.com/browse/QTMOBILITY-64

-jk

Capability for sending SMS

You need to add NetworkServices to the capability list. Man this silly bug costed me 3 days!!! :((

This page was last modified on 11 May 2012, at 06:56.
450 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2012 All rights reserved