PDA

View Full Version : Convert from QByteArray to String ?



probine
25th March 2006, 13:29
I have this statement:

[
QByteArray* messageIn = new QByteArray();
*messageIn = "Hello\n";
cout << "Here I should be able to print Hello\n";
]

I need to conver the QByteArray to:
1. QString
2. String

How ?

wysota
25th March 2006, 13:35
QString has a constructor which takes a QByteArray object as a parameter.
std::string (because I presume this is the subject of the second question) has a constructor that takes a const char* as a parameter and const char * can be obtained from QByteArray using its data() or constData() methods.

probine
25th March 2006, 15:43
I need to be able to print the message contained in the QByteArray in the screen. I am not using any GUI, therefore I am using std::cout.

std::cout << "The msaage in the QByteArray is: " << here should be the message << "\n";

How ?

wysota
25th March 2006, 16:49
QByteArray::data() or QByteArray::constData(). Could you please read the docs first before asking such questions? This is elementary knowledge and it surely doesn't belong to "Qt programming" forum. Moving to "Newbie".