×

Discussion Board

Results 1 to 12 of 12
  1. #1
    Registered User
    Join Date
    May 2009
    Posts
    15

    qstring to TdesC8

    Hello,

    How to convert

    qstring to tDesC8

    Code:
    TXmlEngNode  el = document.CreateElementL(_L8("Nom"),_L8(""),_L8(""));
    	
    	QString qs= ui.txtNom->toPlainText();
    	
    	el.SetValueL(_L8(qs.data()));
    qs.data() is not ok here...

  2. #2
    Super Contributor
    Join Date
    Oct 2007
    Location
    જુનાગઢ - India
    Posts
    3,034

    Re: qstring to TdesC8

    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);

  3. #3
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,166

    Re: qstring to TdesC8

    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.

  4. #4
    Registered User
    Join Date
    May 2009
    Posts
    15

    Re: qstring to TdesC8

    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)

  5. #5
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,166

    Re: qstring to TdesC8

    TBuf is derived from TDesC..

  6. #6
    Super Contributor
    Join Date
    Oct 2007
    Location
    જુનાગઢ - India
    Posts
    3,034

    Re: qstring to TdesC8

    Ohk. Then you need to convert QString to TPtrC16 like.

    Code:
    TPtrC16 textPtr(reinterpret_cast<const TUint16*>(qs.utf16()));
    Then convert textPtr to 8 bit and then pass to your function call.

  7. #7
    Registered User
    Join Date
    May 2009
    Posts
    15

    Thumbs up Re: qstring to TdesC8

    Quote Originally Posted by symbianyucca View Post
    TBuf is derived from TDesC..
    yes but y find reverse solution : QString to TDesc8


    Quote Originally Posted by savaj View Post
    Ohk. Then you need to convert QString to TPtrC16 like.
    ....
    thank, is ok :
    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::NewMaxLC(textPtr.Length());
    	pHeap8->Des().Copy(textPtr);
    	
    	el.SetValueL(pHeap8->Des());
    it only remains for me to write a function




    thank you all for your answers

  8. #8
    Registered User
    Join Date
    May 2009
    Posts
    15

    Red face Re: qstring to TdesC8

    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.

  9. #9
    Super Contributor
    Join Date
    Oct 2007
    Location
    જુનાગઢ - India
    Posts
    3,034

    Re: qstring to TdesC8

    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();

  10. #10
    Registered User
    Join Date
    May 2009
    Posts
    15

    Thumbs up Re: qstring to TdesC8

    Quote Originally Posted by savaj View Post
    Actually you need to remove pHeap8 from cleanup stack. so your prev code works fine if you modify it as follows.

    ...
    is OK ! thank you

  11. #11
    Registered User
    Join Date
    Oct 2007
    Posts
    178

    Post Re: qstring to TdesC8

    This should do the trick:

    Code:
    QString data;
    TPtrC8 dataPtr(reinterpret_cast<const TUint8*>(data.toUtf8().constData()));

  12. #12
    Regular Contributor
    Join Date
    May 2007
    Posts
    468

    Re: qstring to TdesC8

    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

Similar Threads

  1. convert TDesC8 to TChar
    By scc in forum Symbian
    Replies: 12
    Last Post: 2008-05-14, 09:38
  2. Need one HTTP client example
    By vinayakak in forum Symbian Networking & Messaging (Closed)
    Replies: 15
    Last Post: 2008-01-06, 06:44
  3. Cast to TDesC8?
    By kand in forum Symbian
    Replies: 3
    Last Post: 2003-10-31, 08:16
  4. TChar* to TDesC8
    By a_rambhia in forum Symbian Tools & SDKs
    Replies: 0
    Last Post: 2003-03-07, 08:08
  5. TDesC8 and TDesC16
    By httpworks in forum Symbian User Interface
    Replies: 0
    Last Post: 2002-11-07, 07:35

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×