RBuf8 to char * in Symbian C ++

I am loading a text string from a web service in RBuf8 using this kind of code (it works ..)

void CMyApp::BodyReceivedL( const TDesC8& data ) {
    int newLength = iTextBuffer.Length() + data.Length();
    if (iTextBuffer.MaxLength() < newLength)
        {
            iTextBuffer.ReAllocL(newLength);
        }
    iTextBuffer.Append(data);
}

      

I want to convert RBuf8 to a char * string which I can display on a label or whatever .. or for debugging purposes, display in

RDebug::Printf("downloading text %S", charstring);

      

change for clarity.

My transform function looks like this.

void CMyApp :: DownloadCompleteL () {{RBuf16 buf; buf.CreateL (iTextBuffer.Length ()); buf.Copy (iTextBuffer);

    RDebug::Printf("downloaded text %S", buf);
    iTextBuffer.SetLength(0);
    iTextBuffer.ReAlloc(0);                                 
}

      

But it still wrecks. I am using S60 3rd Edition FP2 v1.1

0


source to share


5 answers


What you might need is something like:

RDebug::Print( _L( "downloaded text %S" ), &buf );

      



This tutorial can help you.

+1


source


void RBuf16 :: Copy (const TDesC8 &) will take an 8 bit descriptor and convert it to a 16 bit descriptor.

You should be able to display any 16-bit descriptor on the screen. If it doesn't work, please post the specific API you are using.



When the API can be used with undefined parameters (for example, void RDebug :: Printf (const char *, ...)),% S is used for a "pointer to a 16-bit descriptor". Notice the uppercase% S.

+1


source


Thank you,% S is a helpful reminder.

However, this doesn't work. My transform function looks like this.

void CMyApp::DownloadCompleteL() {
    {
        RBuf16 buf;
        buf.CreateL(iTextBuffer.Length());
        buf.Copy(iTextBuffer);

        RDebug::Printf("downloaded text %S", buf);
        iTextBuffer.SetLength(0);
        iTextBuffer.ReAlloc(0);                 
    }

      

But it still wrecks. I am using S60 3rd Edition FP2 v1.1

0


source


You have to point to a handle pointer in RDebuf :: Printf, so it should be

RDebug::Print(_L("downloaded text %S"), &buf);

      

Although using _L is not recommended. The _LIT macro is preferred.

0


source


As pointed out by quickrecipesonsymbainosblogspotcom, you need to pass a pointer to the handle.

RDebug::Printf("downloaded text %S", &buf); //note the address-of operator

This works because it RBuf8

comes from TDes8

(and the same with 16-bit versions).

-1


source







All Articles