Discussion Board

Results 1 to 12 of 12
  1. #1
    Registered User bbil's Avatar
    Join Date
    May 2009
    Posts
    15
    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
    Nokia Developer Champion savaj's Avatar
    Join Date
    Oct 2007
    Location
    જુનાગઢ - India
    Posts
    3,034
    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 Expert symbianyucca's Avatar
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    28,664
    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 bbil's Avatar
    Join Date
    May 2009
    Posts
    15
    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 Expert symbianyucca's Avatar
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    28,664
    TBuf is derived from TDesC..

  6. #6
    Nokia Developer Champion savaj's Avatar
    Join Date
    Oct 2007
    Location
    જુનાગઢ - India
    Posts
    3,034
    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 bbil's Avatar
    Join Date
    May 2009
    Posts
    15
    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 bbil's Avatar
    Join Date
    May 2009
    Posts
    15
    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
    Nokia Developer Champion savaj's Avatar
    Join Date
    Oct 2007
    Location
    જુનાગઢ - India
    Posts
    3,034
    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 bbil's Avatar
    Join Date
    May 2009
    Posts
    15
    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 ManuMies's Avatar
    Join Date
    Oct 2007
    Posts
    178
    This should do the trick:

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

  12. #12
    Nokia Developer Moderator Jack Torrance's Avatar
    Join Date
    May 2007
    Posts
    468
    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 C++
    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 C++
    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
  •  
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved