作为验证我的代码实际在哪个线程下运行的方法,我使用QThread::currentThreadId()。然而,根据文档,从此函数返回的Qt::HANDLE类型是平台相关的 typedef。void *在我的平台(Linux)上,它只是(无类型指针)的 typedef 。
那么我将如何使用例如打印它qDebug(),以及如何将其转换为 a QString?
我试图使用一些矢量数据的名称struct.我想知道在哪个名字qDebug()
更清楚:
const std::string& testName = "asdfqwer";
qDebug() << testName;
Run Code Online (Sandbox Code Playgroud)
它在构建中给出了错误消息:
Error: no match for 'operator<<' in 'qDebug()() << testName'
Run Code Online (Sandbox Code Playgroud)
我没有更改const std::string&类型的选项.你可以帮我解决这个问题而不改变类型吗?
#include <QCoreApplication>
#include <QByteArray>
#include <QDebug>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QByteArray dataReceivedFromSerialPort;
dataReceivedFromSerialPort.push_back(0x0A);
dataReceivedFromSerialPort.push_back(0x0B);
dataReceivedFromSerialPort.push_back(0x0C);
dataReceivedFromSerialPort.push_back(0x0D);
dataReceivedFromSerialPort.push_back(0x0E);
dataReceivedFromSerialPort.push_back(0x0F);
dataReceivedFromSerialPort.push_back(0x07);
dataReceivedFromSerialPort.push_back(0x02);
dataReceivedFromSerialPort.push_back(0x01);
dataReceivedFromSerialPort.push_back(0x02);
qDebug() << "tostr: " << dataReceivedFromSerialPort.toStdString().c_str();
return a.exec();
}
Run Code Online (Sandbox Code Playgroud)
以上不打印任何值。除了“tostr:”之外,它不会打印任何内容。如果我将 0x0A 存储在 uchar 中,然后将其推送到 qByteArray 中,那么这个问题就会消失。
我能以当前的形式打印它吗?
我一直想知道是否可以使用qDebug()Qt C++中的语句收集用户输入.
我试过像std C++代码那样做:
qDebug() >> myvar;
Run Code Online (Sandbox Code Playgroud)
但它不起作用.
如何阅读stdin使用Qt?
Qt Quick 使用 qDebug执行日志记录,其中标准 Javascript 日志记录方法映射到 Qt 日志类型
console.log() -> qDebug()
console.debug() -> qDebug()
console.info() -> qDebug()
console.warn() -> qWarning()
console.error() -> qCritical()
Run Code Online (Sandbox Code Playgroud)
在这一点上,您失去了 debug() 和 info() 之间的区别。
有没有办法直接在 QML 引擎中为 Javascript 方法注册自定义记录器,而无需通过 qDebug 和qInstallMessageHandler?
我目前在 Windows 7(64 位,旗舰版)上使用 QT Creator 3.2.1 和 Qt 5.3.2(根据我当前项目的要求)。我目前正在做一个 GUI 项目
尽管已执行以下操作,但我无法在“应用程序输出”窗口中看到任何 qDebug 消息:
我可以知道我还应该尝试什么吗?谢谢!
在linux上运行我的Qt5应用程序时,我看不到qDebug,qWarning,qCritical或qFatal的任何输出.我知道我可以使用qInstallMsgHandler安装消息处理程序并查看它们,但这是相当重量级的.
我只想查看qWarning日志,看看是否有任何错误连接的信号.有没有办法看这个日志?一个特殊的命令行选项,一个环境变量?
我想我记得在过去,所有内容都打印到stderr,也许这是Qt5的变化?
我只是想用qDebug以下方法打印一个数字:
qDebug() << QString::number(03001);
Run Code Online (Sandbox Code Playgroud)
但结果是:
"1537"
Run Code Online (Sandbox Code Playgroud)
如果我尝试打印没有第一个零:
qDebug() << QString::number(3001);
Run Code Online (Sandbox Code Playgroud)
结果是正确的:
"3001"
Run Code Online (Sandbox Code Playgroud)
为什么会这样?
我正在使用Qt 5.3.
我尝试将Qt与CLion一起使用.我的问题是qDebug()不打印任何东西,但qInfo(),qWarning(),qCritical()和qFatal()运行良好.这是我的示例代码:
#include <QCoreApplication>
#include <QDebug>
int main(int argc, char *argv[]) {
QCoreApplication a(argc, argv);
qDebug() << "This will not appear";
qInfo() << "This will appear";
qWarning() << "This will appear too";
qCritical() << "This will appear too";
return a.exec();
}
Run Code Online (Sandbox Code Playgroud)
眼镜 :