How to convert TBuf to QString
Article Metadata
Tested with
Devices(s): Emulator
Compatibility
Platform(s): S60 3rd Edition FP1, S60 3rd Edition FP2, S60 5th Edition
Article
Keywords: QString,TBuf
Created: (17 Jan 2009)
Last edited: croozeus
(03 Sep 2009)
Overview
This code snippet demonstrates how to convert TBuf (Symbian Descriptor) to QString (Qt for S60) .
Preconditions
- Install latest Qt for S60 see Qt for S60 - Installation packages
- Check this link for installation guide: How to install the package.
- Go through this article: Getting started with Qt for S60
Source File
#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");
TBuf<10> buf(KMsg);
QString qString((QChar*)buf.Ptr(),buf.Length());
label->setText(qString);
layout->addWidget(label);
win->setLayout(layout);
win->show();
return a.exec();
}

