您当前的位置: 首页 >  ui

DS小龙哥

暂无认证

  • 1浏览

    0关注

    679博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

11.1.5 线程与主线程UI界面交互(友元类)

DS小龙哥 发布时间:2021-10-26 20:20:56 ,浏览量:1

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
关注
打赏
1664009229
查看更多评论
立即登录/注册

微信扫码登录

0.0383s