如何调用qDebug没有附加的空格和换行符? [英] How to call qDebug without the appended spaces and newline?

查看:2663
本文介绍了如何调用qDebug没有附加的空格和换行符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是C ++ / Qt打印函数qDebug,
,但有时我想控制如何,空格和换行符是
,而不是使用默认的qDebug。

I'm using the the C++/Qt print function qDebug, but sometimes I would like to control how ", space and newline is appended and not use the default qDebug.

让我们举一个简单的例子:

Let's take a simple example:

QString var1("some string");
int var2 = 1;
qDebug() << var1 << "=" << var2;

这将打印

"some string" = 1 

但是我们说我不喜欢附加的和空格
,如

But Let's say that I don't like the appended " and space and would like the print to look like

some string=1 

如何调用qDebug?

How to I then call qDebug?

注意: qDebug称为nospace ,但它将删除空格。

Note: There is a function in qDebug called nospace, but it will remove the spaces. But the " is still there.

如果我使用这个:

qDebug().nospace() << var1 << "=" << var2;

我获得:

"some string"=1

但请注意,我仍然没有找到一种方法来删除结束换行符。

But please note that I have still not found a way to get rid of the ending newline.

/感谢

推荐答案

尝试此格式: qDebug(%s =%d ,string,1);
在这种情况下, qDebug 使用 printf 格式化

Try this format: qDebug("%s=%d", "string", 1); In this case qDebug uses printf formatting

PS适合您的示例: qDebug %s =%d,var1.toStdString()。c_str(),var2);

P.S. Adapted for your example: qDebug("%s=%d", var1.toStdString().c_str(), var2);

这篇关于如何调用qDebug没有附加的空格和换行符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆