Results 1 to 8 of 8

Thread: how to print string??

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2007
    Posts
    10
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how to print string??

    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
    Attached Files Attached Files

  2. #2
    Join Date
    Mar 2007
    Posts
    19
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default Re: how to print string??

    If you just want to print one or two you can always use the toStdString() method. So:
    Qt Code:
    1. QString str = "hello";
    2. std::cout<<str.toStdString()<<std::endl;
    To copy to clipboard, switch view to plain text mode 

    would print
    Qt Code:
    1. hello
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    84
    Thanks
    7
    Thanked 2 Times in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: how to print string??

    i still like using the good old printf:

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

    regards,
    jh

  4. The following 2 users say thank you to jh for this useful post:

    alok9871 (5th March 2013), ntp (2nd August 2007)

  5. #4
    Join Date
    Dec 2010
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: how to print string??

    i use
    Qt Code:
    1. qDebug() << "hello world";
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Reading from sockets in a multithreaded program
    By KoosKoets in forum Qt Programming
    Replies: 9
    Last Post: 4th April 2007, 20:43
  2. saving a c string of variable length in a shared memory?
    By nass in forum General Programming
    Replies: 4
    Last Post: 3rd January 2007, 14:40
  3. string to char*?
    By nass in forum General Programming
    Replies: 3
    Last Post: 2nd January 2007, 15:47
  4. Create pixmap image from string
    By Morea in forum Qt Programming
    Replies: 5
    Last Post: 17th November 2006, 16:38
  5. [QT4] QThread and printing a QList<QPixmap>
    By KShots in forum Qt Programming
    Replies: 3
    Last Post: 24th April 2006, 21:44

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
  •  
Qt is a trademark of The Qt Company.