写一段qt/c++代码,实现函数指针,并在子线程运行
时间: 2024-06-06 18:08:41 浏览: 147
C++函数的指针
#include <QtConcurrent/QtConcurrent>
#include <QObject>
#include <QDebug>
class Worker : public QObject {
Q_OBJECT
public:
Worker() {}
public slots:
void doWork()
{
qDebug() << "Worker thread: " << QThread::currentThreadId();
}
};
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
Worker worker;
QFuture<void> future = QtConcurrent::run(&worker, &Worker::doWork);
future.waitForFinished();
return a.exec();
}
// 输出结果:
// Worker thread: 0x7f8f3c001000
阅读全文