在QT 5.12中直接使用cout将提示错误如下:

添加库 #include<iostream>,并将cout&end改为std::cout&std::endl

代码如下:

 #include "mainwindow.h"
#include<iostream>
#include <QApplication> int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show(); std::cout <<"hello world" << std::endl; return a.exec();
}

此时错误警告消失,但是仍无窗口输出;

在qt的工程文件(.pro文件)中加入以下代码:

CONFIG += console

代码如下:

 #-------------------------------------------------
#
# Project created by QtCreator --05T16::
#
#------------------------------------------------- QT += core gui greaterThan(QT_MAJOR_VERSION, ): QT += widgets TARGET = VCICAN
TEMPLATE = app # The following define makes your compiler emit warnings if you use
# any feature of Qt which has been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS # You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0. CONFIG += c++
CONFIG += console SOURCES += \
main.cpp \
mainwindow.cpp HEADERS += \
mainwindow.h FORMS += \
mainwindow.ui # Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target DISTFILES +=

此时cout函数可正常运行

参考:

https://blog.csdn.net/u014563989/article/details/44537727

https://zhidao.baidu.com/question/143715512.html

http://blog.sina.com.cn/s/blog_4f183d960100sdxf.html

http://www.qtcn.org/bbs/simple/?t21816.html

最新文章

  1. 向maven中央仓库提交jar
  2. elasticsearch 之mapping
  3. Asp.net Mvc中分部视图获取后台数据并展示
  4. 第七章 springboot + retrofit(转载)
  5. jsoup
  6. 认识Activity,创建第一个android应用-Hello Word
  7. hdu 栈题1022&amp;1702
  8. postgresql 视图
  9. 请问view controller scene,该如何删除
  10. How-to Dump Keys from Memcache--reference
  11. 理解java的三大特性之多态(三)
  12. NGINX和PHP之间的环境变量传递
  13. 传智播客8月C/C++基础班开班
  14. jQuery性能优化38建议---最引人注目的用户体验!
  15. windows 激活等命令
  16. 2017最新最稳定的合买彩票源码asp+sql2008 新增PK式彩种+全新界面
  17. Spark优化之gc
  18. eclipse jetty 请求的操作无法在使用用户映射区域打开的文件上执行
  19. HTML项目总结
  20. js 操作字典

热门文章

  1. QT:如何重新生成makefile文件
  2. META标签的设置
  3. JS中对小数取整的函数,向上(下),四舍五入取整
  4. (Java多线程系列四)停止线程
  5. 工具类--BeanUtils----Bean转换工具
  6. mybatis逆向工程的text类型的一个小坑
  7. 3分割线左右间距(LinearLayoutManager.VERTICAL)
  8. leetcode-easy-others-461. Hamming Distance
  9. D4下午
  10. log4j.properties 文件,放在 src 下