Qt打印当前线程号
要打印当前线程号,可以使用Qt的QThread类和QThread::currentThreadId()函数。下面是一个示例代码:
#include <QCoreApplication>
#include <QThread>
#include <QDebug>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
qDebug() << "Main Thread ID:" << QThread::currentThreadId();
return a.exec();
}
在上述代码中,我们首先包含了QCoreApplication、QThread和QDebug头文件。然后在main函数中,使用QThread::currentThreadId()函数获取当前线程的ID,并使用qDebug()函数打印出来。最后通过a.exec()运行Qt应用程序。
注意:上述代码在Qt的主线程中运行,如果需要在其他线程中获取线程ID,可以通过继承QThread类并重写其run()函数来实现
原文地址: https://www.cveoy.top/t/topic/iQQs 著作权归作者所有。请勿转载和采集!