| ID | ... | Creation date | 17 January 2009 |
| Platform | S60 3rd Edition FP1, S60 3rd Edition FP2, S60 5th Edition | Tested on devices | Emulator |
| Category | Qt for Symbian | Subcategory | Application |
| Keywords (APIs, classes, methods, functions): HBufC, QString |
This code snippet demonstrates how to convert HBufC (Symbian Descriptor) to QString (Qt for Symbian) .
We can use HBufC when we don't know the size of data that we want to have in the descriptor. Letter 'C' in HBufC stands for constant that means the data is constant but it can also be changed in two ways . First using the assignment operator and another by using the Modifiable pointer descriptor.
#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();
}