×
Namespaces

Variants
Actions

使用Qt Mobility Messaging API检索短信

From Nokia Developer Wiki
Jump to: navigation, search
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: flycarl (18 Nov 2010)
Last edited: hamishwillee (08 May 2013)


Contents

简介

这里的代码演示如何用Qt Mobility的Messaging API检索短信 代码需要以下能力 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
}

代码

与Qt Mobility中其他数据相关的API一样(例如Location API中的地标),Messaging中数据信息的检索有同步 和异步两种方法。通常推荐使用异步的方法。 使用QMessageManager可同步的获得要检索的信息。

m_ids = QMessageManager().queryMessages(QMessageFilter(),QMessageSortOrder::byReceptionTimeStamp(Qt::DescendingOrder),100);

使用QMessageService来异步的检索信息, 与网络调用相关的命令必须通过QMessageService。

m_service->queryMessages(QMessageFilter(),QMessageSortOrder::byReceptionTimeStamp(Qt::DescendingOrder),10);

QMessageService的queryMessages方法执行后,根据检索进度,会发出messagesFound和stateChanged的signal,这里我们做两个slot来接收 这些信号,并执行后续的显示等操作。

void MainWindow::messagesFound(const QMessageIdList& ids)
{
//m_service->queryMessages may result call to this slot
m_ids.append(ids);
qDebug()<<"messagesFound";
 
messagingModel *model = new messagingModel(m_ids, this);
ui->listView->setModel(model);
 
MyDelegate *delegate = new MyDelegate(this);
ui->listView->setItemDelegate(delegate);
}
 
void MainWindow::stateChanged(QMessageService::State newState)
{
//m_service->queryMessages may result call to this slot, can be use to show the loading process.
qDebug()<<"stateChanged"<<newState;
}

显示操作使用了自定义的Model delegate,参照如何使用Model / View / delegate自定义列表,以方便向QML移植。


下载Demo

File:MessagingRetrieve.zip

参考链接

This page was last modified on 8 May 2013, at 00:04.
102 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.

×