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?
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?
You can replace cout with qDebug(),
Qt Code:
#include <QDebug> qDebug() << "Hello World";To copy to clipboard, switch view to plain text mode
The output will be showed in the Application Output.
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.
If you use gui module, and include QApplication header, the output from qDebug() will be showed in the Application Output (in Qt Creator).
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:
#include <iostream> #include <cstdlib> using namespace std; int main(int argc, char *argv[]) { cout << "Hello World!" << endl; system("PAUSE"); // <--- return 0; }To copy to clipboard, switch view to plain text mode
Last edited by saa7_go; 21st August 2010 at 07:31. Reason: updated contents
QTextStream can be used too.
Qt Code:
To copy to clipboard, switch view to plain text mode
thank you for your advice,it works out
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 usingqDebug()<<"hello world";
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
cout is declared in the C++ Standard Library. You need to #include <iostream> and preface cout with the std:: scope:
Qt Code:
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.
Bookmarks