Convert a char into QString as it is done?


Hi I want to convert a char in QString for example I have this:

QString s;
char a = "cadena"

I want to convert a in QString but I do not know how to do it.

asked by omar omar 05.10.2016 в 23:45

1 answer


The code you have entered is incorrect. "cadena" can not be stored in a char , but it is necessary to use char* . In addition, in C ++ the arrangements thus defined are constant by definition, then the correct way to declare it would be:

const char* a = "cadena";

Once this has been solved, to insert a C style string in a QString you can use several options:

// Operador de asignación
s = a;

// Constructor
QString s = a;

// Método append para añadir texto al final de la cadena

There are some other methods that allow you to work with char* , you should take a look at its documentation: link of version 4.8

answered by 06.10.2016 в 08:46