带界面的qt程序显示一个cmd窗口,并且显示qDebug()输出的信息:
void debug()
{
//https://forum.qt.io/topic/56484/solved-attach-console-to-gui-application-on-windows/4
#include <windows.h>
#include <stdio.h>
// detach from the current console window
// if launched from a console window, that will still run waiting for the new console (below) to close
// it is useful to detach from Qt Creator's <Application output> panel
FreeConsole();
// create a separate new console window
AllocConsole();
// attach the new console to this application's process
AttachConsole(GetCurrentProcessId());
// reopen the std I/O streams to redirect I/O to the new console
freopen("CON", "w", stdout);
freopen("CON", "w", stderr);
freopen("CON", "r", stdin);
}
这个函数加到main函数就行:
int main(int argc, char *argv[])
{
debug();
QApplication app(argc, argv);
MainWindow w;
w.show();
return app.exec();
}