Hello,
How to convert
qstring to tDesC8
qs.data() is not ok here...Code:TXmlEngNode el = document.CreateElementL(_L8("Nom"),_L8(""),_L8("")); QString qs= ui.txtNom->toPlainText(); el.SetValueL(_L8(qs.data()));
Hello,
How to convert
qstring to tDesC8
qs.data() is not ok here...Code:TXmlEngNode el = document.CreateElementL(_L8("Nom"),_L8(""),_L8("")); QString qs= ui.txtNom->toPlainText(); el.SetValueL(_L8(qs.data()));
Welcome to forum nokia DiBo.
You can do like followings.
Code:TXmlEngNode el = document.CreateElementL(_L8("Nom"),_L8(""),_L8("")); QString qs= ui.txtNom->toPlainText(); TPtrC8 textPtr(reinterpret_cast<const TUint8*>(qs.utf16())); el.SetValueL(textPtr);
wiki has very similar thing for TBuf to QString in: http://wiki.forum.nokia.com/index.ph...Buf_to_QString
Note that it is 16 bit instead of 8 bit.
thank you
@SavaJe : Only the first letter of the word is stored in TPtrC8
@symbianyucca the link is for conversion Tbuf-> QString and Not QString -> tbuf
(sorry for my English google translation)
TBuf is derived from TDesC..
Ohk. Then you need to convert QString to TPtrC16 like.
Then convert textPtr to 8 bit and then pass to your function call.Code:TPtrC16 textPtr(reinterpret_cast<const TUint16*>(qs.utf16()));
yes but y find reverse solution : QString to TDesc8
thank, is ok :
it only remains for me to write a functionCode:TXmlEngNode el = document.CreateElementL(_L8("Nom"),_L8(""),_L8("")); QString qs= ui.txtNom->toPlainText(); //TPtrC8 textPtr(reinterpret_cast<const TUint8*>(qs.utf16())); TPtrC16 textPtr(reinterpret_cast<const TUint16*>(qs.utf16())); HBufC8 *pHeap8 = HBufC8::NewMaxLC(textPtr.Length()); pHeap8->Des().Copy(textPtr); el.SetValueL(pHeap8->Des());
thank you all for your answers
Hi crash :
Code:testXML Panic E32USER-CBase 71
are what this panic from HBufC8: NewMaxLC?
[EDIT]
ok I found:
Code://HBufC8 *pHeap8 = HBufC8::NewMaxLC(textPtr.Length()); HBufC8 *pHeap8 ; TRAPD(error, pHeap8 = HBufC8::NewMaxLC(textPtr.Length()); CleanupStack::Pop(pHeap8)); pHeap8->Des().Copy(textPtr);
Last edited by bbil; 2009-06-16 at 21:08.
Actually you need to remove pHeap8 from cleanup stack. so your prev code works fine if you modify it as follows.
Code:TXmlEngNode el = document.CreateElementL(_L8("Nom"),_L8(""),_L8("")); QString qs= ui.txtNom->toPlainText(); //TPtrC8 textPtr(reinterpret_cast<const TUint8*>(qs.utf16())); TPtrC16 textPtr(reinterpret_cast<const TUint16*>(qs.utf16())); HBufC8 *pHeap8 = HBufC8::NewLC(textPtr.Length()); pHeap8->Des().Copy(textPtr); el.SetValueL(pHeap8->Des()); CleanupStack::PopAndDestroy();
This should do the trick:
Code:QString data; TPtrC8 dataPtr(reinterpret_cast<const TUint8*>(data.toUtf8().constData()));
There are many conversions available in Mobile Extensions, see Utils class
class XQUTILS_EXPORT XQConversions
{
public:
static QString s60DescToQString(const TDesC& desc);
static HBufC* qStringToS60Desc(const QString& string);
static QString s60Desc8ToQString(const TDesC8& desc);
static HBufC8* qStringToS60Desc8(const QString& string);
static QByteArray s60Desc8ToQByteArray(const TDesC8& desc);
static HBufC8* qByteArrayToS60Desc8(const QByteArray& string);
};
http://wiki.forum.nokia.com/index.php/Mobile_Extensions
Cheers,
Jack