1. moveToThread 将一个object对象转移到线程上,这个QObject就在此线程上发信号,也会在此线程上执行槽函数。
2. 使用了线程之间的队列信号槽模式.
3. 发送了自定义的数据类型
怎么做来做去跟一年前发的帖子很像呢, 翻来覆去的就这点东西
直接看以下烂大街的代码吧。
#include <QApplication>
#include <QCoreApplication>
#include <QObject>
#include <QDebug>
#include <QThread>
#include "MyClassThread1.h"
#include "MyClassThread2.h"
#include "MyClassThread3.h"
#include <QMetaType>
#include "shared.h"
#include "MyClassThread2.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
qDebug()<<"main tid:"<< QThread::currentThreadId();
MyClassThread1 myclassthread1;
myclassthread1.setObjectName("thread1");
QThread thread1;
myclassthread1.moveToThread(&thread1);
QObject::connect(&thread1, &QThread::started, &myclassthread1, &MyClassThread1::getstarted);