ariya.io About Talks Articles

qPrintable

1 min read

In Qt application, outputting printf-like formatted debug message involving QString means using latin1 or utf8 such as:

QString name = "Willy Wonka";
int num = 5;
qDebug("My name is %s, I invite %d children", name.latin1(), num);

But in Qt 4.x, you can use qPrintable function:

QString str = "a chocolate factory";
qDebug("I have %s", qPrintable(str));

For non-formatted output, just use qDebug() as an output stream.

♡ this article? Explore more articles and follow me Twitter.

Share this on Twitter Facebook