11.1.5 线程与主线程UI界面交互(友元类)
【摘要】
11.1.5 线程与主线程UI界面交互(友元类)
1. widget.cpp 文件
#include "widget.h"#include "ui_widget.h" Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget){ ui-...
11.1.5 线程与主线程UI界面交互(友元类)
1. widget.cpp 文件
-
#include "widget.h"
-
#include "ui_widget.h"
-
-
Widget::Widget(QWidget *parent) :
-
QWidget(parent),
-
ui(new Ui::Widget)
-
{
-
ui->setupUi(this);
-
thread_flag=0; //默认线程停止
-
thread.show_ui=this; //给值
-
}
-
-
-
Widget::~Widget()
-
{
-
delete ui;
-
}
-
-
-
//开始执行线程
-
void Widget::on_pushButton_startthread_clicked()
-
{
-
-
thread_flag=!thread_flag;
-
if(thread_flag)
-
{
-
thread.count=0; //清空计数器
-
thread.start(); //开始执行线程
-
ui->pushButton_startthread->setText("停止执行线程");
-
}
-
else
-
{
-
thread.terminate();//终止线程的执行。线程可能会或可能不会立即被终止,这取决于操作系统的调度策略。终止后需要调用QThread::wait()()。
-
thread.wait();
-
ui->pushButton_startthread->setText("开始执行线程");
-
}
-
}
-
-
//线程执行起始点
-
void Thread::run()
-
{
-
-
/* 线程的相关代码 */
-
while
文章来源: xiaolong.blog.csdn.net,作者:DS小龙哥,版权归原作者所有,如需转载,请联系作者。
原文链接:xiaolong.blog.csdn.net/article/details/120953263
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)