Results 1 to 4 of 4

Thread: qDebug style string insertion

  1. #1
    Join Date
    May 2008
    Location
    Melbourne, Australia
    Posts
    136
    Thanks
    9
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default qDebug style string insertion

    hello,

    I want to know how to do qDebug style string insertions. For instance I can go:
    Qt Code:
    1. qDebug("%s is %d today", myName, myAge);
    To copy to clipboard, switch view to plain text mode 

    Python has a similar feature:
    Qt Code:
    1. >>> '%s is %d today' % (myName, myAge)
    To copy to clipboard, switch view to plain text mode 

    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
    Last edited by rbp; 17th March 2009 at 07:36.

  2. #2
    Join Date
    May 2008
    Location
    Melbourne, Australia
    Posts
    136
    Thanks
    9
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: qDebug style string insertion

    I just found QString::sprintf(), although it may be deprecated. That should be good enough for me.

  3. #3
    Join Date
    Mar 2008
    Location
    Houston, Texas, USA
    Posts
    277
    Thanks
    9
    Thanked 17 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Maemo/MeeGo

    Default Re: qDebug style string insertion

    why not

    Qt Code:
    1. QString("%1 is %2 today").arg(myName).arg(myAge);
    To copy to clipboard, switch view to plain text mode 

    That is why sprintf is deprecated.
    Qt-4.7.3 | Gentoo ~amd64 | KDE-4.7
    Aki IRC Client for KDE4 | Qt Documentation

  4. #4
    Join Date
    May 2008
    Location
    Melbourne, Australia
    Posts
    136
    Thanks
    9
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: qDebug style string insertion

    I thought arg() only took strings but I see it also takes a float. I'll use arg() instead.
    Last edited by rbp; 17th March 2009 at 03:28.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.