简体   繁体   English

QThread的一般理解:quit()和isRunning()

[英]General QThread understanding: quit() and isRunning()

When I execute my thread in Qt with start() I can check if it is running with QThread::isRunning () . 当我使用start()在Qt中执行线程时,我可以检查其是否正在使用QThread::isRunning () It returns true in case the thread is still running. 如果线程仍在运行,则返回true After calling quit() i can quit my thread. 调用quit()我可以退出线程。

Now my question: 现在我的问题是:

After calling quit() , my isRunning () query should return false , am I right? 调用quit() ,我的isRunning ()查询应该返回false ,对吗? Equally QThread::isFinished () should return false . 同样, QThread::isFinished ()应该返回false

With this question I just want to confirm that i understood one of the main principles of QThread. 带着这个问题,我只想确认我了解QThread的主要原理之一。

I can be wrong, but documentation tells us that quit and exit(int ) finishes thread event loop. 我可能是错的,但是文档告诉我们quit和exit(int)完成线程事件循环。 But exiting thread event loop doesn't mean that thread is finished. 但是退出线程事件循环并不意味着线程已完成。 You can even run another qthread without even starting event loop by subclassing and reimplementing run method. 您甚至可以通过子类化和重新实现run方法,甚至无需启动事件循环即可运行另一个qthread。 So calling quit method doesn't mean that thread isFinished() return true. 因此,调用quit方法并不意味着线程isFinished()返回true。 Just connect yourself to finished() signal and do what you wanted with finished thread. 只需将自己连接到finish()信号,然后使用完成的线程即可完成您想要的操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM