×
Namespaces

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

使用Qt Mobility Messaging API发送短信

From Nokia Developer Wiki
Jump to: navigation, search

这演示如何用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)


Contents

简介

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


准备条件

编辑pro文件

在pro文件中增加这些行

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

代码

下面的代码片段演示了如何发短信,这里使用了一个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);

下载Demo

183 page views in the last 30 days.
×