PDA

View Full Version : Char array to QString



gab74
12th December 2011, 14:42
I've a char array and i want to convert to QString.

Is there a way to do this ?

char text[24]

to Qstring ???

Lykurg
12th December 2011, 15:10
What about
QString string(text);?

gab74
12th December 2011, 15:48
Infact i try

QString MYstring(text);

But compliler :
no match for call to '(QString) (char [24])'


...Any help ??

Lykurg
12th December 2011, 16:00
char text[] = { 'H', 'e', 'l', 'l', 'o', '\0' };
QString string(text);
qWarning() << text << string; works fine for me. How does your code look like?

gab74
12th December 2011, 16:28
Ok this is my code

struct person {

char name[24];
char surname[24];
};

person P;

strcpy (P.name,"TESTNAME");

QString MYstring(P.name);

The compiler gives the error above...

Lykurg
12th December 2011, 16:37
Hm, builds fine with my
i686-apple-darwin10-gcc-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5666) (dot 3). Which compiler do you use?

gab74
12th December 2011, 17:18
gcc version 4.1.2 under Linux...without any problems....

ChrisW67
12th December 2011, 22:24
If QT_NO_CAST_FROM_ASCII is defined then the conversion constructor from const char* is made private and the compiler would generate an error (similar but not identical to this though). If that is the case, use QString::fromAscii(), QString::fromLatin1(), or QString::fromLocal8Bit() as appropriate.

gab74
13th December 2011, 09:02
I've not defined any QT_NO_CAST_FROM_ASCII....
i used QT 4.2.3...on linux...

Lykurg
13th December 2011, 09:07
Edit: deleted, because my answer was rubbish. Haven't thought it through...

myta212
13th December 2011, 09:52
Hi,
I use linux Ubuntu 10.04 with :
gcc version 4.4.3 (Ubuntu 4.4.3-4ubuntu5)
Using Qt version 4.6.0
and that above method
QString string(text);
THank you

Hi,
I use linux Ubuntu 10.04 with :
gcc version 4.4.3 (Ubuntu 4.4.3-4ubuntu5)
Using Qt version 4.6.0
and that above method working in my computer

QString string(text);
Thank you.

gab74
13th December 2011, 16:54
In older gcc and QT
I have to use

MyString.append(vect_char)