• May 01, 2024, 09:26:16 pm

Author Topic: QString to TDesC  (Read 2740 times)

0 Members and 1 Guest are viewing this topic.

Offline huellif

  • Developer
  • Christmas Santa
  • ****
  • Posts: 402
  • Reputation: 212
QString to TDesC
« on: December 23, 2013, 06:05:22 pm »
Hello,

Do you know what's the fastest and lightest way to convert a QString to a TDesC?
I need it in my project and the descriptor stuff is (sometimes) a bit confusing.

There are a few way, e.g.:
(my project always uses a 13 letters QString, you can replace 13 with qstring.length() for other cases)

Code: [Select]
        //variant 1:
        TPtrC16 tdesc(reinterpret_cast<const TText*>(qstring.constData()));

        //variant 2:
        RBuf tdesc;
        tdesc.CreateL(13);
        for (int i=0 ; i< length ; i++)
        {
            char letter = qstring.at (i).toAscii ();
            tdesc[i]=letter;
        }

        //variant 3:
        RBuf tdesc;
        tdesc.CreateL(13);
        tdesc=(const TUint16 *)qstring.utf16();

        //variant 4:
        TBuf16<13> tdesc;
        tdesc=(const TUint16 *)qstring.utf16();