PDA

View Full Version : cout in Qt



qt_developer
25th May 2012, 07:46
Hi all,

I want to use cout in Qt. I have this code:



#include <QtGui/QApplication>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
QApplication a(argc, argv);

cout << "finish";
return a.exec();
}


but the text "finish" doesn't appear.

What's wrong?

Regards.

Zlatomir
25th May 2012, 08:21
Do you have CONFIG += console in your .pro file? Tell us more about what is happening: what os are you using? the console/terminal doesn't appear? or it appears without output?

And why are you using a QApplication and it's exec()? Do you really need that, because it create an event loop that you will want to close (by connecting a signal to it's quit slot)

qt_developer
25th May 2012, 18:02
Do you have CONFIG += console in your .pro file? Tell us more about what is happening: what os are you using? the console/terminal doesn't appear? or it appears without output?

No, I have added CONFIG += console in my .pro file and now I can see the output, but when the application is closed. I'm using MS Windows. I have run the project from Qt Creator and I expected see the output in "Application output".


And why are you using a QApplication and it's exec()? Do you really need that, because it create an event loop that you will want to close (by connecting a signal to it's quit slot)

No, I have created an empty project by "Qt Gui Application" and QApplication and it's exec() appear by default. What's the best way to create a console project?

Regards!

wysota
25th May 2012, 22:02
No, I have added CONFIG += console in my .pro file and now I can see the output, but when the application is closed.
Add " << endl".