0

I am confused about this: I use Visual Studio 2013

when I am creating project for windows:

When I use qDebug() the output goes to some console output. Is this the console I can use for input? Or I need the one from Qt+=console This code doesnt work there ,so i guess if I want to use that I need console application.

Code 1

    QTextStream out(stdout);
        out << "Please enter login username and password\n";
        out.flush();

however

when I am creating project for linux:

I dont need that console application and it works fine, for example code1 works as desired... I am confused why? Why on linux that works but not in windows?

3 Answers3

3

This is because Windows is strange that way, in that graphical apps don't have console by default. This always annoyed me and I always wound up using a file output to debug. If you wish to really get a console, this might fix it: How to write to the console in a GUI application

Community
  • 1
  • 1
Clusty
  • 117
  • 7
1

Visual Studio has an extra debug console which is for tracing debug output.

This is not the same console as you print and read input from. You can set it to use the standard console but it's not the intention of this one.

qDebug() is mainly used for displaying information about whats going on while running a GUI application.

So when you do an action and only see some reaction you can "trace" what happens internally with qDebug() statements what is happening while not interrupting the GUI execution.

see here for some more information: http://doc.qt.io/qt-5/debug.html#warning-and-debugging-messages

Hayt
  • 5,210
  • 30
  • 37
0

You need to add console option to your Qt project. Assuming you are using qmake, add this to your .pro file:

CONFIG += console

Reference: http://doc.qt.io/qt-5/qmake-variable-reference.html#config

It has no effect on other platforms than Windows I think (on Unix you always have stderr and stdout and stdin the same way and having a GUI does not change that). On Windows it enables console even for GUI apps.

hyde
  • 60,639
  • 21
  • 115
  • 176