PDA

View Full Version : std::cout displaying a hex value instead of a string.



johnny_sparx
7th April 2006, 18:44
I wanted to dump some QStrings to the console. I am using the following code:


std::cout<<"#"<<Item_Parent->child(i)->data(DB_SERIES__PATH,Qt::DisplayRole).toString().c onstData()<<"\n";

It seems fine but I get the following at the console:

#0x815b8aa
#0x816ee42
#0x8175eb2

I want to see the string. I thought constData() would work, but it seems like cout is not processing it right. Suggestions?

munna
7th April 2006, 19:03
try toStdString()

dimitri
8th April 2006, 09:55
Try this:

#include <QString>
#include <iostream>
int main() {
const QString s("test 1234567890");
std::cout << s.constData() << std::endl; // returns QChar *
std::cout << s.toAscii().constData() << std::endl; // returns char *
}
and have a look at QString::constData() (http://doc.trolltech.com/4.1/qstring.html#constData) vs. QByteArray::constData() (http://doc.trolltech.com/4.1/qbytearray.html#constData).