×
Namespaces

Variants
Actions

如何转换HBufC为QString

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata

测试基于
SDK: Qt SDK v1.1.3

兼容于
平台:
Symbian

文章
翻译:
huwell
最后由 hamishwillee 在 11 Oct 2012 编辑


简要概述

下列代码片段演示了如何将HBufC(Symbian描述符)转到QString(Qt for Symbian)

理解HBufC

当我们不支持数据长度时我们可以使用HBufC,这里的'C'表示这个数据是个常量,但我们可以通过两个方法改变,首先是定义符,其次是用修改指针描述符.

源文件

#include <QtGui>
#include <QApplication>
#include <qstring.h>
#include <QLabel>
#include <QVBoxLayout>
#include <QWidget>
 
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QWidget *win = new QWidget;
QLabel *label = new QLabel();
QVBoxLayout *layout = new QVBoxLayout;
_LIT(KMsg,"Hello");
HBufC* buf = KMsg().Alloc();
QString qString((QChar*)buf->Des().Ptr(),buf->Length());
label->setText(qString);
layout->addWidget(label);
win->setLayout(layout);
win->show();
delete buf;
return a.exec();
}
This page was last modified on 11 October 2012, at 04:19.
177 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.

×