qt中如何用qDebug输出彩色调试信息

QT调试技巧:优化printf与qDebug的日志输出体验 本文针对QT开发中常见的调试痛点,详细介绍了如何优化printf与qDebug的日志输出体验。通过配置控制台输出、解决缓冲与编码问题、自定义qDebug格式以及构建轻量级日志系统,帮助开发者实现高效、清晰且可追溯的调试信息管理,从而大幅提升调试效率。 阅读详情

http://blog.youkuaiyun.com/liuguangzhou123/article/details/7481569

原文 http://fanzhichao.blog.hexun.com/22330640_d.html


在终端输出彩色信息有点类似于html的语法,即在要输出的文字前加上转义字符。

指令格式如下\033[*m

这里的*就是转义字符,例如我们要输出一段绿色的文字

qDebug("\033[32mHello!");

输出结果:Hello!

此外还可以设置字体的背景底色、是否加粗、清楚屏幕等等。。。。

其中*的取值如下

  0 : Reset Color Attributes
  1 : 加粗
  2 : 去粗
  4 : 下划线
  5 : 闪烁
  7 : 反色
  21/22 : 加粗 正常
  24 : 去掉下划线
  25 : 停止闪烁
  27 : 反色
  30 : 前景,黑色
  31 : 前景,红色
  32 : 前景,绿色
  33 : 前景,黄色
  34 : 前景,篮色
  35 : 前景,紫色
  36 : 前景,青色
  37 : 前景,白色
  40 : 背景,黑色
  41 : 背景,红色
  42 : 背景,绿色
  43 : 背景,黄色
  44 : 背景,篮色
  45 : 背景,紫色
  46 : 背景,青色
  47 : 背景,白色

其它转义字符命令

清除屏幕 : \033c
  设定水平标位置 : \033[XG
  X为水平标位置。
  设定垂直标位置 : \033[Xd
  Y为垂直标位置。

\033[0K : 删除从标到该行结尾
  \033[1K : 删除从该行开始到标处
  \033[2K : 删除整行 
  \033[0J : 删除标到萤幕结尾
  \033[1J : 删除从萤幕开始到标处
  \033[2J : 删除整个屏幕

Qt调试不止qDebug:手把手教你自定义日志输出到文件和控制台(附颜色配置) 本文深入探讨了Qt开发中如何超越基础的qDebug功能,构建一个高定制化的日志系统。通过详细讲解日志文件存储、彩色控制台输出、日志分级和高级格式化等核心技术,帮助开发者实现更专业、高效的调试方案。文章特别强调了多线程安全、递归避免和性能优化等实战要点,并提供了完整的Logger类实现参考。 阅读详情

相关推荐

Qt日志系统实战:从qInstallMessageHandler到生产级日志管理

在C++和Qt开发中,日志系统是程序可观测性的核心基础设施,它通过捕获、格式化和持久化运行时信息,为调试、监控和问题排查提供关键依据。其核心原理在于拦截和处理应用程序的输出流,通常涉及消息捕获、格式化、输出和管理等模块。一个健壮的日志系统不仅能提升开发调试效率,还能在生产环境中提供稳定的运行状态追踪能力,尤其适用于桌面应用、嵌入式系统和长期维护的中大型项目。本文聚焦于Qt框架下的日志系统实现,通过自定义消息处理器(qInstallMessageHandler)这一关键技术,深入探讨如何构建一个支持线程安全、

weixin_33806914的博客 330

add color output use qdebug

引用自: http://fanzhichao.blog.hexun.com/22330640_d.html   在终端输出彩色信息有点类似于html的语法,即在要输出的文字前加上转义字符。 指令格式如下\033[*m 这里的*就是转义字符,例如我们要输出一段绿色的文字 qDebug("\033[32mHello!"); 输出结果:Hello! 此外还可以设置字体的背景底色...

Linux Job 227

Qt移植EasyLogger,实现彩色日志显示完整工程

Qt移植EasyLogger,实现彩色日志显示完整工程

Qt的qDebug打印加颜色

1、在打印前加如转义字符 qDebug()<<"\033[30m" <<"Hello!"; qDebug()<<"\033[31m" <<"Hello!"; qDebug()<<"\033[32m" <<"Hello!"; qDebug()<<"\033[33m" <&lt...

大AI时代,人性化的信息更加难得可贵 257

QT实现类似qDebug()打印输出之mDebug()

QT实现类似qDebug()打印输出之mDebug(),实现了打印opencv和QT的所有基本数据类型。方便调试

泛微E8流程监控指南:如何用SQL实时追踪审批节点状态?

本文详细介绍了如何利用SQL实时监控泛微E8系统中的审批流程状态,包括核心数据表结构解析、全链路监控SQL实战以及智能预警机制设计。通过数据库直接查询和状态关联分析,帮助企业快速定位卡顿节点,提升流程效率。适用于需要优化OA系统流程管理的企业IT人员和业务主管。

weixin_30687051的博客 439

玩转Qt(1)-输出彩色log

简介我们在Qt Creator中开发程序的时候,经常要做的一件事情,就是看程序的输出Log。一般的log信息都是黑白的,比如这样的: 涛哥在这里告诉大家一个隐藏的技能,那就是输出彩色的log: 从此看到的log,不再是黑白的,而是五颜六色的,生活更加绚丽多彩。 原理要输出彩色信息有点类似于html的语法,即在要输出的文字前加...

武威的涛哥-博客 935

CST仿真实例001:圆极化平板天线仿真

CST仿真实例001:圆极化平板天线仿真实例

weixin_47638568的博客 1万+

qtcreator的文本颜色含义总结

红色:对象名。 紫色:类名。

qbw_csdn的博客 878

YOLOv8冻结层的迁移学习 全网首发

在调用时会创建trainer此时的模型配置更新了,冻结了个p。

qq_42693842的博客 6586

STM32实战:电容触摸屏I2C转USB HID设备全解析

本文详细解析了基于STM32的电容触摸屏I2C转USB HID设备实现方案。通过硬件选型、协议分析和代码实现,展示了如何将GT911触摸屏数据转换为标准USB HID协议,并提供了关键调试经验与性能优化技巧,为智能家居控制面板等应用提供高性价比解决方案。

weixin_42548829的博客 320

qt中如果用qDebug输出彩色调试信息

在终端输出彩色信息有点类似于html的语法,即在要输出的文字前加上转义字符。 指令格式如下\033[*m 这里的*就是转义字符,例如我们要输出一段绿色的文字 qDebug("\033[32mHello!"); 输出结果:Hello! 此外还可以设置字体的背景底色、是否加粗、清楚屏幕等等。。。。 其中*的取值如下 ??0 : Reset Color Attr

lixingchenqq的专栏 654

HFSS实战(三)——过孔via TDR仿真

在上一讲中,主要是通过观察S参数确定via的优化是否达到目标。但S参数只能看到一个整体的结果,并不知道via真实的阻抗是多少?想要单独确定via的阻抗,最好还是通过TDR的仿真。

luohuo9844的博客 1万+

输出调试信息qDebug的应用

(1)  基本语法qDebug("####################1111111111111111");int i=0; QString s = "ss";bool bl = true;qDebug("####################1111111111111111  %d, %s, %d", i, s, bl);//布尔型输出的是0或1在字符界面上运行程序

wangjuns8的专栏 4159

rk3399开发环境的介绍

由于Bluez的介绍文档有限,以及对Linux 系统/驱动概念、D-Bus 通信和蓝牙协议都有要求,加上网络上其实没有一个完整的介绍Bluez系列的文档,所以不管是蓝牙初学者还是蓝牙从业人员,都有不小的难度,学习曲线也相对较陡,所以我有了这个想法,专门对Bluez做一个系统性的介绍,尽可能的涵盖所有内容。

朝气蓬勃 711

【知识图谱】实践篇——基于知识图谱的《红楼梦》人物关系可视化及问答系统实践:part1项目介绍与环境准备

看到这篇文章的你,相信对知识图谱相关概念不在陌生。知识图谱相关内容在实际开发中包含两个部分:1.知识图谱构建,2.知识图谱使用。知识图谱构建过程中涉及内容、技术都比较多。知识图谱的应用也逐渐在我们的生活中随处可见,其中基于知识图谱的问答系统就是其中的一个应用。基于知识图谱的问答系统称做KGQA(knowledge graph question answer),也有人称其为KBQA(knowledge based question answ).基于知识图谱的问答系统通常是使用的是领域知识图谱。下面就结合Git

让算法融入生活,改变生活! 4718

QDebug输出彩色消息

QDebug输出彩色消息 在Qt终端使用QDebug输出彩色信息有点类似于html的语法,即在要输出的文字前加上转义字符。 指令格式如下:\033[*m 这里的*就是转义字符,例如我们要输出一段绿色的文字: qDebug("\033[32mHello!"); 输出结果:Hello! 效果图: 此外还可以设置字体的背景底色、是否加粗、清除屏幕等等。 其中*的取值如下:   0 ...

《好好先生》专栏 1098

c#仿热血江湖

Int32_1 = (int) table.Rows[i]["FLD_初级附魂"],Int32_2 = (int) table.Rows[i]["FLD_中级附魂"],Int32_3 = (int) table.Rows[i]["FLD_是否绑定"],Int32_0 = (int) table.Rows[i]["FLD_进化"],Form1.smethod_1(2, "加载百宝阁物品----没有百宝阁数据");Form1.smethod_1(2, "加载物品商店----没有物品数据");

weixin_42132177的博客 143

QT调试技巧:优化printf与qDebug的输出体验

本文详细介绍了QT开发中优化printf与qDebug调试输出的实用技巧,包括基础输出方式对比、高级格式化控制、输出重定向技术以及多线程环境下的解决方案。通过禁用输出缓存、添加线程标识和使用自定义消息处理器等方法,显著提升调试信息的即时性和可读性,帮助开发者更高效地定位和解决问题。

weixin_27180827的博客 344

深度学习工具包 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")

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

告别混乱调试:QT中如何优雅地管理printf和qDebug输出信息

本文深入探讨了在QT开发中如何优雅管理printf和qDebug调试信息的方法。通过对比基础输出方式、配置控制台输出、格式化美化技巧以及高级日志管理策略,帮助开发者提升调试效率。特别介绍了qDebug的线程安全特性与QT生态集成优势,是QT开发者优化调试流程的实用指南。

weixin_27960253的博客 197

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

【Qt】从零构建Qt命令行应用:项目创建与核心调试

本文详细介绍了如何使用Qt框架从零开始构建命令行应用程序,包括项目创建、核心调试和跨平台部署。通过QCoreApplication和qDebug等工具,开发者可以高效开发跨平台命令行工具,适用于各种自动化任务和后台服务场景。

weixin_30326515的博客 403

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

解决Qt日志卡顿:spdlog共享库无缝集成指南

你是否在Qt项目中遇到过日志写入阻塞UI线程、调试信息混乱或中文乱码问题?本文将通过3个实操步骤+5个避坑技巧,帮助你在Qt应用中高效集成spdlog共享库,实现零卡顿日志系统。读完本文你将掌握:线程安全配置、彩色日志显示、内存管理优化的实战方案。 ## 为什么选择spdlog? spdlog是一个高性能、可扩展的日志库(Log Library,日志库),适用于C++语言环境。相比Qt自带的q...

gitblog_01194的博客 520

Qt开发必备:如何优雅地在GUI程序中添加调试控制台(附条件编译技巧)

本文详细介绍了在Qt GUI程序中优雅添加调试控制台的方法,包括核心机制、工程文件配置技巧和高级调试技术。通过条件编译控制(如CONFIG += console)和多平台适配方案,开发者可以灵活管理调试输出,提升程序诊断能力。文章还涵盖了开发环境集成、日志分级系统和生产环境解决方案,帮助开发者构建完整的调试体系。

weixin_30872499的博客 628
上一篇: 屏蔽qDebug等调试信息
下一篇: Qt之打包发布(NSIS详解)
cocoasprite
博客等级 码龄14年 72粉丝 101原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值