+ Reply to Thread
Results 1 to 6 of 6

Thread: where is cout in Qt Creator

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

    Question where is cout in Qt Creator

    hi,i'm new in Qt.i use Qt Creator on Windows,but i get a problem here:
    After i type in : cout << "hello world",where did it come out? i can't see it.why didn't it like visual c++ just poping a window which claimed "hello world" cheerfully?

  2. #2
    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.

  3. #3
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,939
    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.

  4. #4
    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 08:31. Reason: updated contents

  5. #5
    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 

  6. #6
    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

+ Reply to Thread

Similar Threads

  1. where is cout
    By hqking1988 in forum General Programming
    Replies: 3
    Last Post: 22nd August 2010, 04:35
  2. QProcess : force cout to be sent
    By Nyphel in forum Qt Programming
    Replies: 2
    Last Post: 6th April 2007, 00:05
  3. cout problem
    By mickey in forum General Programming
    Replies: 3
    Last Post: 2nd March 2007, 19:12
  4. How to cout in Qt ?
    By probine in forum Qt Programming
    Replies: 4
    Last Post: 15th December 2006, 01: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, 09: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