首页| 论坛| 消息

标题:新建一个线程,一些参数数据怎么给他?
作者:hpplel
日期:2018-06-21 14:05
内容:

如题!
看网上一些例子都是子线程发信号,主线程接受。
但是,对于新建的线程,怎么给他需要操作的数据参数呢?
用信号槽?这样对吗:我给线程的槽传信号,线程的槽把传入的数据写到线程的变量里吗?然后通知run运行?(怎么通知也不会啊!)
请大家帮忙谢谢~!能提供个简单的实例最好啦~


#1 [uidab 06-21 16:00]
QThread * thread = new QThread;
QtThreadFuncClass* funcclass = new QtThreadFuncClass;
funcclass->moveToThread(thread);
QObject::connect(thread, &QThread::started, funcclass, &QtThreadFuncClass::ThreadFunc, Qt::DirectConnection);
thread->start();
看第4行,你可以写类似的 ,最后一个参数请自己学习。QObject::connect(this, this的信号, funcclass, &QtThreadFuncClass::某个Func, Qt::QueuedConnection);
#2 [ustone 06-21 20:27]
通过MyThread构造函数的参数?
#3 回 ustone 的帖子 [hpplel 06-22 09:57]
ustone:通过MyThread构造函数的参数? (2018-06-21 20:27) 
谢谢,试了下这个可以
#4 回 uidab 的帖子 [hpplel 06-22 09:58]
uidab:QThread * thread = new QThread;
    QtThreadFuncClass* funcclass = new QtThreadFuncClass;
     funcclass->moveToThread(thread);
    QObject::connect(thread, &QThread::started, funcclass, &Q .. (2018-06-21 16:00) 
参数数据在funcclass 里设置是吗?
这个类QtThreadFuncClass;能给个小例子吗?

回复 发表
主题 版块