Search for sprintf function in QString.
char *data = "string";
QString str;
str.sprintf("%s",data);
qDebug() << str;
Search for sprintf function in QString.
char *data = "string";
QString str;
str.sprintf("%s",data);
qDebug() << str;
Last edited by p3c0; 18th April 2012 at 13:18. Reason: updated contents
you can just
char* data = "string";
QString str;
str = data;
This should work also.
Thanks..it worked for me..
sprintf is useful for other stuff
QString has constructor that takes a char* (and, as kito said, the operator= also can take char*).
You may need to take into consideration encoding of the C-style string also: is it plain ASCII, Latin 1, UTF-8 or some other supported encoding? QString has a range of static conversion functions for handling these differences if the default constructor/operator=() handling is not quite right.
Zlatomir (19th April 2012)
Bookmarks