×
Namespaces

Variants
Actions
Revision as of 19:59, 17 November 2010 by flycarl (Talk | contribs)

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

使用Qt Mobility Messaging API发送短信

From Nokia Developer Wiki
Jump to: navigation, search
  • 适用平台:S60 3rd Edition FP1, S60 3rd Edition FP2, S60 5th Edition Symbian^3
  • 运行设备: Qt Creator IDE
  • 关键字:Qt Mobility, Messaging, Chinese

Contents

简介

这演示如何用Qt Mobility的Messaging API发送短信,

Article Metadata
Tested with
Devices(s): Nokia 5800 and N8.
Compatibility
Platform(s): S60 3rd Edition, FP1, FP2
S60 5th Edition Symbian^3
Symbian
Article
Keywords: QMessageService, QMessage, Chinese
Created: (18 Nov 2010)
Last edited: flycarl (17 Nov 2010)


Overview

这里的代码演示如何用Qt Mobility的Messaging API发送短信,自Qt Mobility 1.1.0可以发送中文短信。 代码需要以下能力 NetworkServices LocalServices ReadUserData WriteUserData UserEnvironment ReadDeviceData WriteDeviceData 。自签名不够用,至少需要 开发者签名 ,也可以用 Open Signed Online来测试。


Prerequisite

.pro file

Modify your .pro file as follows.

CONFIG += mobility
MOBILITY = messaging
 
symbian {
 
TARGET.CAPABILITY = NetworkServices \
LocalServices \
ReadUserData \
WriteUserData \
UserEnvironment \
ReadDeviceData \
WriteDeviceData
}

Code

下面的代码片段演示了如何发短信,这里使用了一个UI界面的lineEdit来存放要发送的字符,可以是中文字符,这样做避免了关于字符编码的冗长讨论。实际操作中也不建议将中文字符硬编码在代码里,需要使用中文字符的地方应遵循Qt的国际化和本地化的操作。

    QMessageService service;
 
QMessage message;
 
QMessageAddressList toList;
 
QMessageAddress::Type addrType(QMessageAddress::Phone);
 
toList.append(QMessageAddress(addrType, "13800000000"));//电话号码//这里可以设置群以号码
 
message.setType(QMessage::Sms);//短信类型
 
message.setTo(toList);
 
message.setBody(tr(ui->lineEdit->text());
 
service.send(message);

Download Code Example

191 page views in the last 30 days.
×