QT : 屏蔽qDebug调试信息

qDebug().noquote()、qDebug().nospace()和 DEFINES+= QT_NO_DEBUG_OUTPUT作用 阅读详情
AI摘要

本文介绍了三种在Qt项目中屏蔽调试输出的方法:1. 在main函数前直接定义宏;2. 通过Qt .pro文件设置预处理器宏;3. 在VC项目的预处理器定义中加入宏。这些方法可以有效地关闭qDebug等函数的输出。

DEFINES += QT_NO_WARNING_OUTPUT
DEFINES += QT_NO_DEBUG_OUTPUT

C:\Qt\Qt5.7.0\5.7\msvc2013\include\QtCore\qlogging.h
[cpp]  view plain  copy
  1. #define QT_NO_QDEBUG_MACRO while (false) QMessageLogger().noDebug  
  2. #if defined(QT_NO_DEBUG_OUTPUT)  
  3. #  undef qDebug  
  4. #  define qDebug QT_NO_QDEBUG_MACRO  
  5. #endif  
  6. #if defined(QT_NO_INFO_OUTPUT)  
  7. #  undef qInfo  
  8. #  define qInfo QT_NO_QDEBUG_MACRO  
  9. #endif  
  10. #if defined(QT_NO_WARNING_OUTPUT)  
  11. #  undef qWarning  
  12. #  define qWarning QT_NO_QDEBUG_MACRO  

  1. #endif  

方法1:直接在main函数之前加入宏定义。注意,这种方法,好像无法保证全局所有类中的qDebug被屏蔽。最好还是用第二种或第三种方法。


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <QtCore/QCoreApplication>
 
#define QT_NO_DEBUG_OUTPUT      //屏蔽debug输出
#define QT_NO_WARNING_OUTPUT    //屏蔽warning输出 
#include <QtDebug>
int  main( int  argc,  char  *argv[])
{
     QCoreApplication a(argc, argv);
 
         qDebug( "Funciton debug" );
     qDebug()<< "Stream debug" ;
     
     return  a.exec();
}

方法2:
在Qt工程文件.pro里面添加
 DEFINES += QT_NO_WARNING_OUTPUT\ QT_NO_DEBUG_OUTPUT 
然后clear项目重新编译即可屏蔽qDebug()的输出.

方法3:
在VC项目配置里C/C++ /Preprocessor /Preprocessor Definitions属性里面加入宏定义:QT_NO_DEBUG_OUTPUT


如何打包Qt程序? 如何打包Qt程序? 准备一个test项目,在Debug时期的效果图是这样的 将此时的Debug模式切换为Release 阅读详情

相关推荐

Qt基础-屏蔽qDebug()、qWarning()调试和警告消息

本文讲解Qt如何-屏蔽qDebug()、qWarning()调试和警告消息

qq_30725967的博客 717

Qt程序的调试版和发行版对应的宏定义QT_DEBUG和QT_NO_DEBUG

在Qt编程中,有时候需要针对Debug调试版和Release发行版做条件编译,做不同的处理,比如有时在Debug版中需要在控制台打印日志,在Release版中将日志写入到文件中。 Qt中提供了QT_DEBUG这个调试版宏,以及QT_NO_DEBUG这个发行版宏。 在https://stackoverflow.com/中看到了很老的一篇文章:Does Qt offer a (guaranteed) debug definition? Does Qt offer a (guaranteed) debug def

ccf19881030的专栏 6317

Qt Debug信息屏蔽在什么场合下会用到?

当你的主线程中还有另外的定时任务处理时,你就必须屏蔽这些大量的输出语句了,不然,这些任务虽然也能执行,但是大量的刷屏信息,估计你也受不了。还有一种场合,就是主线程中,一般是ui线程,也可以是没有ui的没有线程存在的程序进程中,你在主线程中以每秒输出一个调试信息的速度去运行程序,尤其是某些数据收发过程,尤其是在调试一些逻辑过程的时候,看看哪里逻辑对错,若是使用调试器,调试起来会比较慢,而且经常晕头转向的跳转跳转,还不如一个输出语句,然后ctrl+r运行来得快捷。所以,不同场合不同方式,怎么用得爽怎么来吧。..

有问题或资源连接有缺失的可以私信公众号新潮看世界获取 546

QT 的QDebug无法输出日志

1、 工程文件 pro CONFIG += console c++11 # 可以配置多个,但是每个之间要有空格,不建议一行配置多个 如果加了console后还不能输出,有可能是 禁止输出了 可以把以下的定义去掉 DEFINES+= QT_NO_DEBUG_OUTPUT 或者: CONFIG(debug ,debug|release){ DEFINES -= QT_NO_DEBUG_OUTPUT }else{ DEFINES += QT_NO_DEBUG_OUTPUT } 在deb

我不是码农的博客~~~ 2835

Latex 大修/小修 major/minor revision 及回复审稿意见

本博客为解决 Manuscript 提交的为latex版本只有PDF,如何解决文章大修/小修的问题。比较推荐方法二,操作简单。方法一也不错就是安装texlive有点费时,推荐vscode+latexdiff , 可以参考。本博客为解决 Manuscript 提交的为latex版本只有PDF,如何解决文章大修/小修的问题。修改完后将相应的 latex 压缩文件和 Manuscript pdf 上传到投稿系统中即可。

Sophia_hust的博客 4063

水下机器人仿真平台选型指南:从AirSim到Unity3D的深度对比

本文深入对比了AirSim+UE和Unity3D两大水下机器人仿真平台的核心架构、传感器仿真能力和水下环境建模特点。AirSim+UE凭借高精度物理仿真和丰富传感器支持成为专业研发首选,而Unity3D则以快速开发和灵活扩展见长。文章为研发团队提供了全面的选型指南,帮助优化水下实验的仿真效率与成本。

weixin_29009669的博客 459

QT : 屏蔽qDebug调试信息

在VC项目配置里C/C++ /Preprocessor /Preprocessor Definitions属性里面加入宏定义:QT_NO_DEBUG_OUTPUT。方法1:直接在main函数之前加入宏定义。注意,这种方法,好像无法保证全局所有类中的qDebug被屏蔽。最好还是用第二种或第三种方法。然后clear项目重新编译即可屏蔽qDebug()的输出.在Qt工程文件.pro里面添加。

木牛的博客 43

六自由度机械臂运动学分析及其轨迹规划

六自由度机械臂轨迹规划 通过对比三次多项式插值法与五次多项式插值法的效果,选取后者对机械臂进行轨迹规划,将运动学解导入Matlab Robotics Toolbox仿真,得到各关节角度、速度和加速度与时间关系曲线。 三次多项式插值法 三次多项式有4个待定系数,可同时对起始点和目标点的角度和角速度给出约束条件。 数学公式 MATLAB代码 五次多项式插值法 五次多项式有6个待定系数,可同时对起始点和...

两条眉毛 6万+

QT qml屏蔽掉所有qdebug等调试信息。

在交叉编译到开发板中,如果多个线程,经常打印出调试信息,影响后续对板端控制,可以进行屏蔽。文件io等也会屏蔽掉。

hsyhd的博客 406

第三篇:学习InternVL2.0(探讨代码之训练模块版)

InternVL2的训练模块

qq_69051120的博客 1254

【LVGL-SquareLine Studio】

SquareLine Studio做为LVGL官方推出的PC端开发工具,采用所见即所得的开发方式,大大减少了敲代码方式开发UI的时间。LVGL拖转开发工具。

sinat_23896491的博客 1万+

Qt开发之路43---Qt屏蔽qDebug调试信息

一:局部屏蔽 如下,在当前文件加宏定义QT_NO_WARNING_OUTPUT 和 QT_NO_DEBUG_OUTPUT #define QT_NO_DEBUG_OUTPUT //屏蔽debug输出 #define QT_NO_WARNING_OUTPUT //屏蔽warning输出 二:全局屏蔽 如下,在.pro文件中添加宏定义QT_NO_WARNING_OUTPUT 和 QT_NO_DEBUG_OUTPUT DEFINES += QT_NO_WARNI

木木木 的博客 1352

Linux存储软件栈剖析之第5篇:F2FS文件系统

F2FS是三星专为NAND闪存设计的开源文件系统,通过异地更新、磨损均衡等机制优化闪存特性。其架构采用层次化存储管理(Block→Segment→Section→Zone)和多日志区域设计,基于数据热度分类(热/温/冷数据)提升性能。核心创新包括节点地址表(NAT)解决级联更新问题,以及基于成本的垃圾回收算法。F2FS通过检查点机制确保崩溃一致性,并利用并行访问能力充分发挥闪存性能优势,显著降低写放大效应,延长设备寿命。

指尖动听知识库 206

Qt屏蔽qDebug打印

做项目免不了qDebug打印调试信息。随着项目的完善,于是在控制台看到到处都是qDebug的信息,这不但影响程序的效率,而且也不容易定位真正的错误信息。于是想到了QT中可以屏蔽qDebug打印调试信息,然后在项目中调试的时候用qDebug项目完结把它屏蔽掉就OK。下面是我使用宏自定义的输出格式: #ifndef OUT_FORMAT #define OUT_FORMAT "{ FILE:["&...

刘一儿(嵌入式) 1641

小秋SLAM入门实战ubuntu所有文章汇总

ubuntu 终端如何停止快速打印的输出以及恢复命令 ubuntu 终端如何快速打开当前路径下的图形化窗口界面? killall -9用途用法 ps -xu | grep这个命令的用途 linux 下 top命令显示的是内存是堆内存吗? zip分割和合并 关闭除当前 GNOME 终端窗口以外的所有其他 GNOME 终端窗口 如何在安装系统后设置短密码 【如何使用getrusage获取消耗的CPU时间和进程使用的最大物理内存】 【webots安装使用教程】 Linux系统下查看当前运行的进程和线程的几种方法

小秋 AI SLAM 入门实战教程 1421

信号与电源完整性5:轨道塌陷噪声/电源轨道噪声分析及降低解决方案

经过上一节关于串扰的分析,我们已经清楚,噪声问题不仅仅来源于信号网络;电源和地网络所产生的噪声,被反馈到其所在的元器件和信号网络时,其破坏力也是巨大的;本节所讨论的轨道塌陷噪声就是一个典型的实例。在经过电源的地网络的电流发生改变时,在电源和地之间的阻抗上将产生一个压降;由于该压降的产生,用电元件的电压将直接被拉低,甚至可能对电路产生功能性的错误。接下来硬小二将详细的分析电源轨道噪声和降低其的解决方法。...

fydar的博客 2252

Qt 屏蔽qDebug 输出

在pro 文件中定义 QT_NO_DEBUG_OUTPUT 这个宏,就可以屏蔽qDebug 的输出了 DEFINES += QT_NO_DEBUG_OUTPUT 那么为什么定义这个宏就可以屏蔽qDebug 的输出呢?看qlogging.h 中的定义 #define QT_NO_QDEBUG_MACRO while (false) QMessageLogger().noDebug #if de...

逸冰小子 1456

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

QT屏蔽qDebug的方法

QT屏蔽qDebug的方法 在工程文件.pro里面添加 DEFINES += QT_NO_WARNING_OUTPUT\ QT_NO_DEBUG_OUTPUT 然后clean 再rebuild ;这样就能屏蔽qDebug的输出信息了 参考:https://www.cnblogs.com/yikezhuixun/p/6061024.html ...

心跳的博客 1023

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

屏蔽Qt的qWarning() qDebug()语句输出

1.屏蔽Qt的qWarning()语句输出 在工程文件.pro文件中添加 DEFINES += QT_NO_WARNING_OUTPUT 2.屏蔽Qt的qDebug()语句输出 在工程文件.pro文件中添加 DEFINES += QT_NO_DEBUG_OUTPUT 3.两个都屏蔽 在工程文件.pro文件中添加 DEFINES += QT_NO_WARNING_

好行者 2765

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Qt小技巧集锦

除了/*...*/和//...还可以使用下面的方式注释 #if 0 需要注释的代码 #endif123 2、Qt使用cout输出更详细的调试信息 使用C语言全局宏输出调试信息所在文件、行号 #define cout qDebug()<<"["<<__FILE__<<":"<<__LINE__<<"]" 构造函数中: c...

wu694128的博客 600

QT屏蔽qDebug()、qWarning()打印信息

转载: https://blog.csdn.net/qq_35173114/article/details/81037315   QT编译程序时,有时候需要用qDebug()打印信息,但太多了之后手动一个个屏蔽也麻烦,删除却又怕下次需要,这时候就需要预定义宏 在工程文件.pro里面添加 DEFINES += QT_NO_WARNING_OUTPUT\  QT_NO_DEBUG_OUTPUT...

zhenguo26的博客 2313

qt中屏蔽qDebug

pro文件中#//屏蔽qDebug()输出 DEFINES+=QT_NO_DEBUG_OUTPUT

MichaelSrc的草稿簿 1255

Qt屏蔽输出流技巧

Qt程序中调试会加入qDebug语句,但有时候想屏蔽掉,用下面的方法很方便实现。 在Qt项目文件添加以下定义: 屏蔽qInfo() DEFINES += QT_NO_INFO_OUTPUT 屏蔽qDebug() DEFINES += QT_NO_DEBUG_OUTPUT 屏蔽qWarning() DEFINES += QT_NO_WARNING_OUTPUT

热土程序园,利他愉己~ 752

麒麟系统下QT运行一端时间内存占满的问题

这就是Qt常规的方法,发布时,可使用屏蔽宏,屏蔽调所有的qDebug和qWarn输出。在.pro文件中添加宏定义;

weixin_45790559的博客 967

Qt开发应用程序Debug与Release设置

一般来说,release版的可执行程序在体积上比起debug版要小很多(数倍甚至数十倍的差异),而且由于剥离了许多调试信息及符号等运行效率相对也高一些。

exlink2012的专栏 4870

qDebug小坑

  使用qDebug打印输出,但这里有个注意的地方是,qDebug是一个宏,可以被屏蔽,比如定义了:QT_NO_DEBUG_OUTPUT宏,即qDebug()后面的语句将不再执行,会导致程序意想不到的后果。 qDebug() << system("myapp");   除了qDebug宏,还有qWarning和qInfo也是需要注意的。 ...

Qt君 385
上一篇: QT 学习之键盘事件( keyPressEvent)
下一篇: C语言中的#号和##号的作用
HarkerYX
HarkerYX 优质创作者: 嵌入式与硬件开发技术领域 优质创作者: 嵌入式与硬件开发技术领域 领域专家: 操作系统技术领域 领域专家: 操作系统技术领域
博客等级 码龄16年 3万+粉丝 1285原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值