PDA

View Full Version : Conversion Char Array to string



anafor2004
2nd May 2008, 13:58
Hi
I want to show my array's on a label, so i want to convert my char array to string for a label.
How may i do this?

mitro
2nd May 2008, 15:04
Just use QLabel::setText(const QString &) function with your array as the argument. QString class will make conversion for you.

For instance:

char array[] = "Some text";
QLabel label;
label.setText(array);

aamer4yu
2nd May 2008, 19:56
by the way,
why dont u use QString itself instead of the char[] ??

kunalnandi
3rd May 2008, 09:07
Hello,

jst convert ur array[] to QString..




char array[] = "Hello World";
QString *str = NULL;

str = array;

QLabel tempLabel;

tempLabel.setText( str );

anafor2004
6th May 2008, 10:34
it is not working,:(

ChristianEhrlicher
6th May 2008, 13:59
it is not working,:(
Very very good error description... :mad:

What does not work? What did you try to fix it? Did you even try to solve it the way the former posts suggested?

mitro
6th May 2008, 14:35
The last method is incorrect. You cannot just assign a pointer to char array to a pointer to QString. Why don't use the solution I've suggested earlier? There is no need to make things harder. If you need QString not only to set for a label but for other aims too, just instantiate QString with your array as a parameter:

char array[] = "Some text";
QString string(array);