PDA

View Full Version : how to print string??



pratik
10th July 2007, 13:51
i want to know how we can print any string in qt as cout and qwarning are not working.

Is there any other way for this??

please help

thanks

guilugi
10th July 2007, 13:55
Look for qPrintable(...) ;-)

Shaitan
10th July 2007, 14:19
Is QString::toLatin1() what you are looking for??

QString text="text";
int ret = QMessageBox::warning(this, tr("My Application"), text.toLatin1(), QMessageBox::Ok);

J.

Gopala Krishna
10th July 2007, 14:48
Is QString::toLatin1() what you are looking for??

QString text="text";
int ret = QMessageBox::warning(this, tr("My Application"), text.toLatin1(), QMessageBox::Ok);

J.

QString::toLatin1() returns QByteArray neither QString nor const char *.
Also QMessageBox takes QString as parameter which doesn't cause problem. But qWarning, qDebug takes const char * as parameter and you can use qPrintable to convert QString to const char *

twells55555
11th July 2007, 12:30
Hi,

If you want to use cout to print, I have attached two files to this email...qstd.cpp and qstd.h. To use the standard cout syntax include these files in your project and add the namespace using command - using namespace qstd - to any scope in which you want to use cout (and include the "qstd.h" header file of course).

I did not write these files myself, but stumbled upon them somewhere on the web while trying to solve a problem similiar to yours when I first started with Qt. I give full credit, thanks and kudo's to the unamed author....cout has worked flawlessly for me.

Hope this helps....

tim

BatteryCell
12th July 2007, 07:00
If you just want to print one or two you can always use the toStdString() method. So:


QString str = "hello";
std::cout<<str.toStdString()<<std::endl;


would print

hello

jh
13th July 2007, 22:20
i still like using the good old printf:

QString str;
printf("%s\n", str.toLatin1().constData());
fflusg(stdout);

regards,
jh

a-atalla
25th December 2010, 16:38
i use

qDebug() << "hello world";