Results 1 to 9 of 9

Thread: where is cout in Qt Creator

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2010
    Location
    Salatiga, Indonesia
    Posts
    160
    Thanks
    11
    Thanked 32 Times in 29 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    1

    Default Re: where is cout in Qt Creator

    You can replace cout with qDebug(),

    Qt Code:
    1. #include <QDebug>
    2.  
    3. qDebug() << "Hello World";
    To copy to clipboard, switch view to plain text mode 

    The output will be showed in the Application Output.

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: where is cout in Qt Creator

    No, that won't work either. All output is directed to stdout (or stderr), but a Qt Windows program never opens a console window unless you add a configuration option.

    Add CONFIG += console in your .pro file
    This will open a console window when you start your program.

  3. #3
    Join Date
    Jun 2010
    Location
    Salatiga, Indonesia
    Posts
    160
    Thanks
    11
    Thanked 32 Times in 29 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    1

    Default Re: where is cout in Qt Creator

    Quote Originally Posted by tbscope View Post
    No, that won't work either. All output is directed to stdout (or stderr), but a Qt Windows program never opens a console window unless you add a configuration option.
    If you use gui module, and include QApplication header, the output from qDebug() will be showed in the Application Output (in Qt Creator).

    Quote Originally Posted by tbscope View Post
    Add CONFIG += console in your .pro file
    This will open a console window when you start your program.
    The problem is when you don't use event loop, console window will close immediately (when using Qt Creator). In windows, i usually add CONFIG += console in my .pro and the following line

    Qt Code:
    1. #include <iostream>
    2. #include <cstdlib>
    3.  
    4. using namespace std;
    5.  
    6. int main(int argc, char *argv[])
    7. {
    8. cout << "Hello World!" << endl;
    9. system("PAUSE"); // <---
    10. return 0;
    11. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by saa7_go; 21st August 2010 at 07:31. Reason: updated contents

  4. #4
    Join Date
    Jul 2010
    Posts
    11
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Re: where is cout in Qt Creator

    QTextStream can be used too.
    Qt Code:
    1. QTextStream out(stdout);
    2. out << QString("Some text");
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Aug 2010
    Posts
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: where is cout in Qt Creator

    thank you for your advice,it works out

Similar Threads

  1. where is cout
    By hqking1988 in forum General Programming
    Replies: 3
    Last Post: 22nd August 2010, 03:35
  2. QProcess : force cout to be sent
    By Nyphel in forum Qt Programming
    Replies: 2
    Last Post: 5th April 2007, 23:05
  3. cout problem
    By mickey in forum General Programming
    Replies: 3
    Last Post: 2nd March 2007, 18:12
  4. How to cout in Qt ?
    By probine in forum Qt Programming
    Replies: 4
    Last Post: 15th December 2006, 00:47
  5. std::cout displaying a hex value instead of a string.
    By johnny_sparx in forum Qt Programming
    Replies: 2
    Last Post: 8th April 2006, 08:55

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.