Convert char to QString
-
wrote on 5 Oct 2016, 21:48 last edited by
Sorry for this maybe but how i can convert a char to QString? i was searching and i tried but i couldnt....
-
wrote on 5 Oct 2016, 22:06 last edited by
QString test(QChar('a'));
-
Sorry for this maybe but how i can convert a char to QString? i was searching and i tried but i couldnt....
wrote on 5 Oct 2016, 22:08 last edited byHi @RIVOPICO,
how i can convert a char to QString?
There's lots of ways, and it really depends on how your
char
is encoded. For example, if its a simple ASCII / Latin1 char, then one option is to use QChar, such as:const char c = 'C'; qDebug() << QString(QChar::fromLatin1(c));
Or, for example, if you mean a
char *
to a string of characters, then it may be appropriate to use QString::fromLocal8Bit()const char * const str = "STR"; qDebug() << QString::fromLocal8Bit(str);
Cheers.
-
Hi @RIVOPICO,
how i can convert a char to QString?
There's lots of ways, and it really depends on how your
char
is encoded. For example, if its a simple ASCII / Latin1 char, then one option is to use QChar, such as:const char c = 'C'; qDebug() << QString(QChar::fromLatin1(c));
Or, for example, if you mean a
char *
to a string of characters, then it may be appropriate to use QString::fromLocal8Bit()const char * const str = "STR"; qDebug() << QString::fromLocal8Bit(str);
Cheers.
1/5