std::cout displaying a hex value instead of a string.
I wanted to dump some QStrings to the console. I am using the following code:
Code:
std::cout<<"#"<<Item_Parent->child(i)->data(DB_SERIES__PATH,Qt::DisplayRole).toString().constData()<<"\n";
It seems fine but I get the following at the console:
Code:
#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?
Re: std::cout displaying a hex value instead of a string.
Re: std::cout displaying a hex value instead of a string.
Try this:
Code:
#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() vs. QByteArray::constData().