Results 1 to 4 of 4

Thread: cout to stdout in Qt Console Application

  1. #1
    Join Date
    Jul 2012
    Posts
    244
    Thanks
    27
    Thanked 15 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default cout to stdout in Qt Console Application

    What is the right way to write to stdout in a Qt Console Project?

    This appears to be a popular question, which is commonly answered with "use qDebug() << QString(...)".
    Indeed, that is exactly what i want, but qDebug() writes to stderr, not stdout.

    What would be the stdout equivalent to qDebug()?

  2. #2
    Join Date
    Nov 2007
    Posts
    55
    Thanks
    1
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: cout to stdout in Qt Console Application

    #include <QTextStream>

    . . .

    QTextStream cout(stdout);

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: cout to stdout in Qt Console Application

    Quote Originally Posted by tuli View Post
    What is the right way to write to stdout in a Qt Console Project?
    Qt Code:
    1. std::cout << "xyz" << std::endl;
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #4
    Join Date
    Nov 2007
    Posts
    55
    Thanks
    1
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: cout to stdout in Qt Console Application

    with QTextStream you can also use Qt objects. Things like



    #include <QTextStream>
    ....
    QTextStream cin(stdin);
    QTextStream cout(stdout);

    cout << "Enter your name: " << endl;
    QString s = cin.readLine();
    cout << "Your name is: " << s;

Similar Threads

  1. Redirecting stdout to a console in Qt
    By geotdw in forum Qt Programming
    Replies: 1
    Last Post: 24th March 2012, 10:43
  2. Replies: 1
    Last Post: 19th September 2011, 10:43
  3. Replies: 3
    Last Post: 19th March 2011, 05:02
  4. error in QTextStream cout(stdout)
    By kaushik_acharya in forum Newbie
    Replies: 7
    Last Post: 9th April 2009, 13:24
  5. Replies: 4
    Last Post: 27th March 2008, 09:21

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.