Qt GUI程序带命令行

VS + QT:

项目--属性--链接器--系统--子系统--控制台 (/SUBSYSTEM:CONSOLE)

QT Creator 用如下方法:

Windows does not really support dual mode applications.

To see console output you need to create a console application

CONFIG += console

However, if you double click on the program to start the GUI mode version then you will get a console window appearing, which is probably not what you want. To prevent the console window appearing you have to create a GUI mode application in which case you get no output in the console.

One idea may be to create a second small application which is a console application and provides the output. This can call the second one to do the work.

Or you could put all the functionality in a DLL then create two versions of the .exe file which have very simple main functions which call into the DLL. One is for the GUI and one is for the console.

 
  •  
    Yes, this is what I've come to realise - two apps! – Rob Jul 30 '10 at 9:01
  •  
    Having a small console app to call the main GUI app is fine, but is there any way to feed back the output to the console app in real time so the user can see what's going on, or to show typical output for things like -h, --version etc? – iforce2d May 27 '13 at 7:11
  •  
  • 3
    You can free the console by calling FreeConsole. So your application may decide in which mode it will work and then hide the console if running in GUI mode. – Alexander Dunaev Jun 10 '13 at 2:57
  •  
    Be warned that FreeConsole has incredibly dangerous behaviour on Windows 8: stackoverflow.com/questions/12676312/… – Kim Jun 29 '17 at 12:10
原文地址:https://www.cnblogs.com/liujx2019/p/14338320.html