Conversion wchar a string to pass it to unicode Qt

0

Hi, I'm doing the following conversion:

wchar_t buffer[5];
QString string = QString::fromWCharArray(buffer);
char *utf8encoded = string.toUtf8();

But it seems to give me the following error:

  

'initializing': conversion of 'QByteArray' can not be performed   'char *' No conversion operator is available defined by   the user who can perform this conversion, or can not   call the operator

I followed the documentation but I still have the same error ...

    
asked by Perl 04.11.2016 в 23:28
source

1 answer

1

The problem is that the method toUtf8() of the class QString returns a variable of type QByteArray , while you are trying to store the result in a variable of type char* .

So you should change this:

char *utf8encoded = string.toUtf8();

Because of this:

QByteArray utf8encoded = string.toUtf8();

But if you need to work with data of type char* , in the class QByteArray you have a method called data() that returns a pointer to the data. This way you could do the following:

char *utf8encoded = string.toUtf8().data();

Greetings.

    
answered by 05.11.2016 / 10:11
source