[Qt-interest] QString to char array
Robin Helgelin
lobbin at gmail.com
Mon Dec 29 07:43:05 CET 2008
On Mon, Dec 29, 2008 at 05:31, Avishek_Sharma <Avishek_Sharma at satyam.com> wrote:
> Hi,
> I came across this piece of code to convert/copy from QString to char array.
>
> char arr[255];
> QString str;
> strcpy(arr,str.toAscii().constData());
>
> will this code work?
Yes, it works, but your example is a dangerous when you are copying to
a fixed sized array, better use strncpy in such cases.
The best however would be if you could keep it as a QString the whole
way through your application.
--
regards,
Robin
More information about the Qt-interest-old
mailing list