PDA

View Full Version : qDebug style string insertion



rbp
17th March 2009, 03:16
hello,

I want to know how to do qDebug style string insertions. For instance I can go:

qDebug("%s is %d today", myName, myAge);

Python has a similar feature:

>>> '%s is %d today' % (myName, myAge)

It would be helpful if I could do these style of manipulations in my Qt C++ program. Is there a proper way to do this, or do I have to hack the string around to inject my content.

thanks,
Richard

rbp
17th March 2009, 03:19
I just found QString::sprintf(), although it may be deprecated. That should be good enough for me.

ComaWhite
17th March 2009, 03:23
why not



QString("%1 is %2 today").arg(myName).arg(myAge);


That is why sprintf is deprecated.

rbp
17th March 2009, 04:24
I thought arg() only took strings but I see it also takes a float. I'll use arg() instead.