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