Qt : Convert QString to char

Qt : Convert QString to char

QString have very much feature compared with char data type. But, in some of conditions, we need to Qt : convert QString to char datatype. This is a sample function how Qt : Convert QString to char datatype :

const char *QString2char(QString str)
{
	QByteArray byteArray;
	const char *cstr;

	byteArray = str.toUtf8();
	cstr = byteArray.constData();

	return(cstr);
}

This is the sample method, how we can use Qt : Convert QString to char function above :

QString mystring;
const char *char_data;

mystring = "this is a string";
char_data = QString2char(mystring);

What do you think? Are you think this Qt : Convert QString to char is very simple :)

totosugito

Hi, This is my notes when I try something. Maybe, this is NOT THE BEST SOLUTION for your problems. If you have other method or idea that better with my post, please share in this blog. Thank for visiting my site.

More Posts - Website

Leave a Reply