Convert a char into QString as it is done?

2

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
source

1 answer

1

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
s.append(a);

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