在qt中写控制台程序
时间:2011-03-19 来源:清清飞扬
找到两种方法可以写控制台程序
第一种,直接用标准c++写,具体如下:
1. 建立 HelloConsole 目录
2. 在该目录下新建 main.cpp
- #include <iostream>
 - using namespace std;
 - int main(int argc, char **argv)
 - {
 - cout << "Hello!" << endl;
 - return 0;
 - }
 
3. 在 HelloConsole 目录下输入
qmake -project
建立项目文件 HelloConsole.pro
4. 修改 HelloConsole.pro,在其中加入一行
CONFIG += console
5. 在 HelloConsole 目录下输入
qmake
mingw32-make
6. 生成的可执行文件在debug目录下
第二种,使用qt自带的类,编译过程与第一种一致,不同的是代码:
- #include <QTextStream>
 - static QTextStream cout(stdout, QIODevice::WriteOnly);
 - int main(int argc, char **argv)
 - {
 - cout << "Hello!" << endl;
 - return 0;
 - }
 
在qt中写控制台程序,关键是在项目文件中加上一行
CONFIG += console
 相关阅读 更多 + 
    
  









