您当前的位置: 首页 >  qt

txwtech

暂无认证

  • 0浏览

    0关注

    813博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

QT使用QThread创建线程的方法

txwtech 发布时间:2022-08-16 23:05:09 ,浏览量:0

 

QT使用QThread启动线程的方法 

 创建项目文件基类选择QDialog,添加两个按钮

分别按钮右键-》转到槽,添加代码

点击启动线程,

thread2.start();默认调用my_thread类的run函数
#include "dialog.h"
#include "ui_dialog.h"
#include 


Dialog::Dialog(QWidget *parent)
    : QDialog(parent)
    , ui(new Ui::Dialog)
{
    ui->setupUi(this);
}

Dialog::~Dialog()
{
    delete ui;
}


void Dialog::on_pushButton_start_clicked()
{
    thread2.start();
    ui->pushButton_start->setEnabled(false);
    ui->pushButton_stop->setEnabled(true);
}

void Dialog::on_pushButton_stop_clicked()
{
    if(thread2.isRunning())
    {
        thread2.stop();
        ui->pushButton_start->setEnabled(true);
        ui->pushButton_stop->setEnabled(false);
    }
    else
    {
        qDebug()            
关注
打赏
1665060526
查看更多评论
0.2036s