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?
Printable View
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(),
Code:
#include <QDebug> qDebug() << "Hello World";
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
Code:
#include <iostream> #include <cstdlib> using namespace std; int main(int argc, char *argv[]) { cout << "Hello World!" << endl; system("PAUSE"); // <--- return 0; }
QTextStream can be used too.
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 usingQuote:
qDebug()<<"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:
Code:
std::cout << "Hello world!" <<std::endl;
Or (bad practice) add a "using namespace std;" declaration after including iostream.