- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
qt线程同步2(QT thread synchronization 2)
qt线程同步2(QT thread synchronization 2)
Qt thread synchronization
Using threads in Qt is not as cumbersome as in Mfc, which provides the QThread thread class and provides a way to create a new thread. Threads perform their operations by overloading the QThread:: run () function, which is similar to the thread class in Java.
To achieve a simple inheritance from the QThread user thread class, the code is as follows.
Class Thread: public QThread
{
Public:
Thread ();
Void, stop ();
Protected:
Virtual, void, run ();
Private:
Bool m_stop;
};
Thread:: Thread ()
{
M_stop = false;
}
Void Thread:: stop ()
{
M_stop = true;
}
Void Thread:: run ()
{
While (... M_stop)
{
Sleep (1);
QDebug (vic.MINg!);
}
QDebug (end!);
}
In the example above, you can see that the thread is not difficult to write!
When you start the thread, you can call the function QThread:: start () to start the Thread thread object.
When you stop the thread, you can call the function QThread:: terminate (), but the terminate () function does not immediately terminate the thread, and when the thread terminates depends on the scheduling policy of the operating system. Note that the terminate () function is too sinister, it may be in arbitrary thread execution step terminates execution, resulting in unpredictable consequences (such as modifying an important data), in addition, it also did not give any chance to clean up the scene of the thread (such as the release of memory and lock etc.).
Therefore, the stop thread can, as shown in the code above, write the function stop () to make its thread soft exit.
When the thread is stopped, you should call the QThread:: wait () function, which causes the thread to block wait until it exits or goes out of time.
It seems that compiling multithreaded applications under Unix or Linux must also add the following line to the.Pro file, which tells qmake to use the thread version of the Qt library. On Windows, the Qt library defaults to threading.
CONFIG = thread
Introduced the creati
您可能关注的文档
- joo1(joo1).doc
- java面试纠错题目大全(Java interview error correction topics).doc
- jorinde and joringel(jorinde和joringel).doc
- js document对象(i document对象).doc
- jdbc 访问各种数据库 url 语法(总结篇)(JDBC access various database URL syntax (summary)).doc
- java面象对象编程(Java object like programming).doc
- jsp input限制输入(JSP input restrict input).doc
- js语句及语法(JS statements and syntax).doc
- juniper基本配置入门(Introduction to basic configuration of juniper).doc
- js语法(JS syntax).doc
- quartus常见错误分析[eda](Quartus common error analysis [eda]).doc
- qxq磁控式软启动器做工精细,外观合理,质量上乘(Qxq magnetron type soft starter, fine workmanship, reasonable appearance, high quality).doc
- ral系列颜色(Ral series colors).doc
- pthread手册(pthread手册).doc
- redhat linux命令大全总汇详解最新发布完整珍藏版(RedHat Linux command Daquan confluence detailed, the latest release of the full collection Edition).doc
- remeber _java_c_sharp(Remeber Java C Sharp _ _ _).doc
- reverb参数中英文对照(The reverb parameter English control).doc
- rfc2245(rfc2245).doc
- rflp分析(rflp分析).doc
- python自定义(Python custom).doc
最近下载
- 山东省泰安市2025届高三四模检测(泰安四模)英语试题及答案.docx VIP
- 2024-2025学年深圳中学初中部七年级入学分班考试数学试卷附答案解析.pdf
- GB50424-2015 油气输送管道穿越工程施工规范.docx VIP
- (2025秋新版)人教版三年级数学上册全册教案.docx
- 采矿工程毕业设计论文-麦地掌煤矿150万吨矿井初步设计.doc VIP
- 德隆煤矿90万吨初步设计.doc VIP
- 2025年山东黄金集团井下技能工人招聘(2000人)考试备考题库及答案解析.docx VIP
- 直肠癌手术编码.pptx VIP
- 2025秋统编版(2024)道德与法治一年级上册教学设计(全册) .pdf
- Unlock2 Unit4 第一篇听力讲解及答案.pptx VIP
文档评论(0)