Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copying the content of a character array to a QString in Qt

I have a character pointer that in any run can have different length. For example:

char*  myChar;

In one run its content can be "Hi" and in another run it can be "Bye".

I want to copy the content of myChar to a QString, for example if I have:

QString myString;

I want to copy the content of myChar to myString; how can I do that?

like image 342
TJ1 Avatar asked Oct 19 '12 13:10

TJ1


1 Answers

Use QString::fromLatin1(const char*), QString::fromLocal8Bit(const char*) or QString::fromUtf8(const char*) as appropriate. Note that you can't just copy the data because QStrings contain 16-bit Unicode characters. It will always need to decode the 8-bit representation.

like image 142
Dan Milburn Avatar answered Sep 20 '22 00:09

Dan Milburn