View Full Version : Char array to QString
gab74
12th December 2011, 13: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, 14:10
What about
QString string(text);?
gab74
12th December 2011, 14:48
Infact i try
QString MYstring(text);
But compliler :
no match for call to '(QString) (char [24])'
...Any help ??
Lykurg
12th December 2011, 15: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, 15: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, 15: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, 16:18
gcc version 4.1.2 under Linux...without any problems....
ChrisW67
12th December 2011, 21: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, 08:02
I've not defined any QT_NO_CAST_FROM_ASCII....
i used QT 4.2.3...on linux...
Lykurg
13th December 2011, 08:07
Edit: deleted, because my answer was rubbish. Haven't thought it through...
myta212
13th December 2011, 08: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, 15:54
In older gcc and QT
I have to use
MyString.append(vect_char)
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.