gpt4 book ai didi

c++ - Qt 5.7\n 行为

转载 作者:行者123 更新时间:2023-11-28 01:36:37 24 4
gpt4 key购买 nike

在 Qt 5.7 控制台应用程序中:

#include <QCoreApplication>
#include <QtDebug>

int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);

QString s = "MDJ\nTest.\n";
qDebug() << "MDJ\nTest.\n";
qDebug() << s;

/* Prints:
MDJ
Test.

MDJ\nTest.\n
*/

return a.exec();
}

即\n 在直接调试打印中按预期工作,但在调试打印(假定内容相同)变量时仅被视为两个普通字符。

我在 Qt 5.7 Widget 应用程序中也遇到了类似的问题。

我已经搜索了文档、stackoverflow 和 Qt Center,但一直无法发现我做错了什么。

有人可以为我指出解决方案吗?

最佳答案

文档给你提示:

<< QString()

Normally, QDebug prints the string inside quotes and transforms non-printable characters to their Unicode values (\u1234).
To print non-printable characters without transformation, enable the noquote() functionality. Note that some QDebug backends might not be 8-bit clean.

对比

<< const char*

Writes the '\0'-terminated string, s, to the stream and returns a reference to the stream. The string is never quoted nor transformed to the output, but note that some QDebug backends might not be 8-bit clean.

解决方案:qDebug().noquote() << "some\nspecial\nchars\n\tincluded"

关于c++ - Qt 5.7\n 行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49018943/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com