Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

How to convert HBufC to QString

From Wiki
Jump to: navigation, search

This code snippet demonstrates how to convert a Symbian heap-based HBufC descriptor to a Qt QString. For more information about converting between string types see Using Qt and Symbian C++ Together#Strings

Article Metadata
Tested with
SDK: Qt SDK v1.1.3
Devices(s): Emulator
Compatibility
Platform(s): S60 3rd Edition FP1, S60 3rd Edition FP2, S60 5th Edition
Platform Security
Signing Required: Self-Signed
Capabilities: None
Article
Keywords: HBufC, QString
Created: kamaljaiswal (17 Jan 2009)
Last edited: hamishwillee (30 May 2013)

Understanding HBufC

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. This is more information on HBufC in Fundamentals of Symbian C++/Descriptors


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");
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 30 May 2013, at 06:38.
53 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.

×