Results 1 to 9 of 9

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,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.

  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

  7. #7
    Join Date
    Sep 2017
    Posts
    23
    Thanks
    8
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: where is cout in Qt Creator

    it depending on what is the type of your app, console app or gui app. if it was console it would be appeared on console application but if you were using a gui, it should be appeared in the application output only when using
    qDebug()<<"hello world";

  8. #8
    Join Date
    Sep 2019
    Posts
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: where is cout in Qt Creator

    Hello,

    I've been using Qt4 and C++ for making programs in computer graphics, now switching to Gt5. How can I use 'cout' to print the variables in the console at run-time? It doesn't work, even when I add the libraries. Here's the error message: error: ‘cout’ was not declared in this scope



    https://stackoverflow.com/questions/3886105/how-to-print-to-console-when-using-qt https://writemyessaytoday.net/write-my-essay-in-6-hours https://www.qtcentre.org/threads/33506-where-is-cout-in-Qt-Creator

  9. #9
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: where is cout in Qt Creator

    cout is declared in the C++ Standard Library. You need to #include <iostream> and preface cout with the std:: scope:

    Qt Code:
    1. std::cout << "Hello world!" <<std::endl;
    To copy to clipboard, switch view to plain text mode 

    Or (bad practice) add a "using namespace std;" declaration after including iostream.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.