- 主题:请教:qthread里这句话。
【It is important to remember that a QThread instance lives in the old thread that instantiated it, not in the new thread that calls run(). This means that all of QThread's queued slots and invoked methods will execute in the old thread】. Thus, a developer who wishes to invoke slots in the new thread must use the worker-object approach; new slots should not be implemented directly into a subclassed QThread.
括号里这句是指两种模型都是这样?还是特指第二种模型?
应该是特指模型二,因为模型一不会去改写qthread。
Unlike queued slots or invoked methods, 【methods called directly on the QThread object will execute in the thread that calls the method. 】When subclassing QThread, keep in mind that the constructor executes in the old thread while run() executes in the new thread. If a member variable is accessed from both functions, then the variable is accessed from two different threads. Check that it is safe to do so.
括号里这句话到底是模型一还是模型二?
。
--
修改:zhanghaoX FROM 124.64.17.*
FROM 124.64.17.*
这个跟 qt 的 signal/slot 的事件循环和 QueuedConnection 有关。
现代 qt 编程,别去管这事了。统一用 QtConcurrent 吧。
我虽然知道是怎么回事,但解释起来不会比官方文档简单。
而且我从学 Qt 到现在,基本上没直接用过 QThread.
【 在 zhanghaoX (环顾四方有效) 的大作中提到: 】
: 【It is important to remember that a QThread instance lives in the old thread that instantiated it, not in the new thread that calls run(). This means that all of QThread's queued slots and invoked methods will execute in the old thread】. Thus, a de
: 括号里这句是指两种模型都是这样?还是特指第二种模型?
: Unlike queued slots or invoked methods, 【methods called directly on the QThread object will execute in the thread that calls the method. 】When subclassing QThread, keep in mind that the constructor executes in the old thread while run() executes in
: ...................
--
修改:hgoldfish FROM 112.47.122.*
FROM 112.47.122.*
低层偏硬件些还是得用啊
刚发现串口用在线程里的那个成员变量跨线程的问题,所以理一下
。
【 在 hgoldfish 的大作中提到: 】
: 这个跟 qt 的 signal/slot 的事件循环和 QueuedConnection 有关。
:
: 现代 qt 编程,别去管这事了。统一用 QtConcurrent 吧。
: ...................
--
FROM 124.64.17.*
这个invoked method 到底指啥?非queued slot?
。
【 在 hgoldfish 的大作中提到: 】
: 这个跟 qt 的 signal/slot 的事件循环和 QueuedConnection 有关。
:
: 现代 qt 编程,别去管这事了。统一用 QtConcurrent 吧。
: ...................
--
FROM 124.64.17.*
QMetaObject::invokeMethod() ?
这个是就是 signal/slot 的底层 API
【 在 zhanghaoX (环顾四方有效) 的大作中提到: 】
: 这个invoked method 到底指啥?非queued slot?
: 。
--
FROM 121.205.116.*
不也包括queued的吗?为毛分开说?
。
【 在 hgoldfish 的大作中提到: 】
: QMetaObject::invokeMethod() ?
:
: 这个是就是 signal/slot 的底层 API
: ...................
--
FROM 124.64.17.*
对模型二
queuedslots和invokedmethods都是被别人调用的,都必定是在old线程中执行。
qthread本身调用的自己的成员函数,如果是在非run中调用,就是在old线程执行,如果是在run中调用,就是在新线程中调用的。
应该是这样理解吧
。
【 在 hgoldfish 的大作中提到: 】
: 这个跟 qt 的 signal/slot 的事件循环和 QueuedConnection 有关。
:
: 现代 qt 编程,别去管这事了。统一用 QtConcurrent 吧。
: ...................
--
修改:zhanghaoX FROM 124.64.17.*
FROM 124.64.17.*
你说的模型2是subclass QThread?如果是这种的话,QThread::run是另一个线程的入口,QThread的其他部分还在创建它的线程中。
【 在 zhanghaoX 的大作中提到: 】
: 对模型二
: queuedslots和invokedmethods都是被别人调用的,都必定是在old线程中执行。
: qthread本身调用的自己的成员函数,如果是在非run中调用,就是在old线程执行,如果是在run中调用,就是在新线程中调用的。
: ...................
--
FROM 123.123.134.*
你看第二段括号里的话。
【 在 zhcon 的大作中提到: 】
: 你说的模型2是subclass QThread?如果是这种的话,QThread::run是另一个线程的入口,QThread的其他部分还在创建它的线程中。
:
: 【 在 zhanghaoX 的大作中提到: 】
: ...................
--
FROM 124.64.17.*
还一个问题,模型一,work假如有两个slot,movetothread,run起来后,两个slots在一个线程执行,还是两个,还是别的情形,?
。
【 在 hgoldfish 的大作中提到: 】
: 这个跟 qt 的 signal/slot 的事件循环和 QueuedConnection 有关。
:
: 现代 qt 编程,别去管这事了。统一用 QtConcurrent 吧。
: ...................
--
FROM 124.64.17.*