当前位置: 首页 > news >正文

微信上打开连接的网站怎么做上海排名优化seobwyseo

微信上打开连接的网站怎么做,上海排名优化seobwyseo,做网站面临的困难,张雪峰谈电子商务专业QT使用线程的两种方式 1.案例进度条 案例解析: 如图由组件一个进度条和三个按钮组成,当点击开始的时候进度条由0%到100%,点击暂停,进度条保持之前进度,再次点击暂停变为继续,点击停止按钮进度条停止。 案…

QT使用线程的两种方式

1.案例进度条

案例解析:
如图由组件一个进度条和三个按钮组成,当点击开始的时候进度条由0%到100%,点击暂停,进度条保持之前进度,再次点击暂停变为继续,点击停止按钮进度条停止。
案例流程:
1.创建qwidget工程
2.添加四个控件,转到槽函数

在这里插入图片描述

2.使用线程方式一

2.1创建一个类继承QThread,重写run方法

2.2mythread.cpp

#include "mythread.h"
#include <QDebug>
MyThread::MyThread()
{}
void MyThread::stop()
{running=false;
}
//暂停继续
void MyThread::threadStop(bool flag)
{pause=flag;
}
//重写run方法
void MyThread::run()
{qDebug()<<"线程id:"<<currentThreadId();while (1) {//触发信号while(running){while (pause) {msleep(100);}if(value>100)value=0;emit valChage(value++);msleep(100);}exit(0);}
}

2.3mythread.h

#ifndef MYTHREAD_H
#define MYTHREAD_H
#include <QThread>
#include <QDebug>
//继承QThread重写run方法
class MyThread : public QThread
{Q_OBJECT
public slots:void stop();void threadStop(bool flag);
signals:void valChage(int);
public:MyThread();void run();
private:int value=0;bool running=true;bool pause=false;
};#endif // MYTHREAD_H

2.4widget.h

#ifndef WIDGET_H
#define WIDGET_H#include <QWidget>
#include <QProgressBar>
#include<QThread>
#include "mythread.h"
namespace Ui {
class Widget;
}class Widget : public QWidget
{Q_OBJECTpublic:explicit Widget(QWidget *parent = 0);~Widget();
signals:void stop();void threadStop(bool);
private slots:void on_pushButton_clicked();void on_pushButton_3_clicked();void on_pushButton_2_clicked();private:Ui::Widget *ui;MyThread *mythread;
};
#endif // WIDGET_H

2.5widget.cpp

#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent) :QWidget(parent),ui(new Ui::Widget)
{ui->setupUi(this);}Widget::~Widget()
{delete ui;
}void Widget::on_pushButton_clicked(){mythread= new MyThread();//绑定信号与槽函数connect(mythread,&MyThread::valChage,ui->progressBar,&QProgressBar::setValue);//延时connect(mythread,&MyThread::finished,mythread, &QObject::deleteLater);connect(this,&Widget::stop,mythread,&MyThread::stop);connect(this,&Widget::threadStop,mythread,&MyThread::threadStop);mythread->start();ui->pushButton->setEnabled(false);}void Widget::on_pushButton_3_clicked()
{emit stop();
}
void Widget::on_pushButton_2_clicked()
{static bool flag=true;if(flag){emit threadStop(true);ui->pushButton_2->setText("继续");flag=false;}else{emit threadStop(false);ui->pushButton_2->setText("暂停");flag=true;}
}

3.使用线程方式二

3.1创建类继承QObject

在这里插入图片描述

3.2qworker.h

这里的槽函数实现直接写在.h文件中,不够规范,只便与学习观看,切不要效仿。

#ifndef QWORKER_H
#define QWORKER_H
#include <QObject>
#include <QThread>
#include <QApplication>
class qworker : public QObject
{Q_OBJECT
public:explicit qworker(QObject *parent = nullptr);signals:void dataChanged(int);
public slots:void doWorking(){while (!sFlag) {if(current>=100)current=0;while (pFlag) {QThread::msleep(10);//接收来自外部进程的事件,否则收不到信号QApplication::processEvents();}emit dataChanged(current++);QThread::msleep(10);QApplication::processEvents();}sFlag=false;current=0;}void pause(bool flag){pFlag=flag;}void stop(){sFlag=true;}
private://进度条int current=0;//暂停bool pFlag=false;//停止bool sFlag=false;
};
#endif // QWORKER_H

3.3widget.h

#ifndef WIDGET_H
#define WIDGET_H#include <QWidget>
//引入qworker.h
#include "qworker.h"namespace Ui {
class Widget;
}class Widget : public QWidget
{Q_OBJECTpublic:explicit Widget(QWidget *parent = 0);~Widget();
signals:void working();void pause(bool);void stop();
private slots:void on_pushButton_clicked();void on_pushButton_2_clicked();void on_pushButton_3_clicked();
c
private:Ui::Widget *ui;qworker *worker;QThread thread;
};
#endif // WIDGET_H

3.4widget.cpp

#include "widget.h"
#include "ui_widget.h"Widget::Widget(QWidget *parent) :QWidget(parent),ui(new Ui::Widget)
{ui->setupUi(this);worker=new qworker();//移动到线程中worker->moveToThread(&thread);//开始connect(this,&Widget::working,worker,&qworker::doWorking);//暂停connect(this,&Widget::pause,worker,&qworker::pause);//停止connect(this,&Widget::stop,worker,&qworker::stop);connect(worker,&qworker::dataChanged,ui->progressBar,&QProgressBar::setValue);thread.start();
}
Widget::~Widget()
{delete ui;
}
void Widget::on_pushButton_clicked()
{emit working();
}void Widget::on_pushButton_2_clicked()
{static bool flag=true;if(flag){emit pause(true);flag=false;ui->pushButton_2->setText("继续");}else{emit pause(false);flag=true;ui->pushButton_2->setText("暂停");}
}
void Widget::on_pushButton_3_clicked()
{emit stop();
}

4.总结

两种方式都可以完成案例需求:

方式一:

1.通过继承QThread类重写run方法

2.重写类MyThread的虚函数void run();,即新建一个函数protected void run(),然后对其进行定义。

3.在需要用到多线程的地方,实例MyThread,然后调用函数MyThread::start()后,则开启一条线程,自动运行函数run()。

4.当停止线程时,调用MyThread::wait()函数,等待线程结束,并且回收线程资源。

方式二:

1.继承QObject类,创建对象。

2.通过moveToThread将派生类对象移动到一个线程中。

3.通过信号连接派生类的槽函数,将耗时的工作放到这个槽函数中运行。

4.用信号QThread::finished绑定槽函数QThread::deleteLatater(),在线程退出时,自动销毁该线程和相关资源。

5.通过QThread的start()函数开启多线程。


文章转载自:
http://dinncobilinguality.tqpr.cn
http://dinncoperiblast.tqpr.cn
http://dinncosubaverage.tqpr.cn
http://dinncodane.tqpr.cn
http://dinncoamphigamous.tqpr.cn
http://dinncofhwa.tqpr.cn
http://dinncozagazig.tqpr.cn
http://dinncoreenlistment.tqpr.cn
http://dinncopyre.tqpr.cn
http://dinncohumous.tqpr.cn
http://dinncoconnive.tqpr.cn
http://dinncoaquosity.tqpr.cn
http://dinncorepute.tqpr.cn
http://dinncopasquinade.tqpr.cn
http://dinncosponsor.tqpr.cn
http://dinncosystematizer.tqpr.cn
http://dinncosabulite.tqpr.cn
http://dinncorubbed.tqpr.cn
http://dinncoosborn.tqpr.cn
http://dinncointimacy.tqpr.cn
http://dinncoorjonikidze.tqpr.cn
http://dinncoexhalant.tqpr.cn
http://dinncoreminiscent.tqpr.cn
http://dinncouncase.tqpr.cn
http://dinncomachiavelli.tqpr.cn
http://dinncotestatrix.tqpr.cn
http://dinncoorlon.tqpr.cn
http://dinncocadence.tqpr.cn
http://dinncoplacentography.tqpr.cn
http://dinncodissever.tqpr.cn
http://dinncodehumidify.tqpr.cn
http://dinncounattained.tqpr.cn
http://dinncoarchwise.tqpr.cn
http://dinncomalcontent.tqpr.cn
http://dinncocalamitous.tqpr.cn
http://dinncoxylyl.tqpr.cn
http://dinncopassion.tqpr.cn
http://dinncogiggit.tqpr.cn
http://dinncounrhymed.tqpr.cn
http://dinncoestriol.tqpr.cn
http://dinncoendoenzyme.tqpr.cn
http://dinncowhirlwind.tqpr.cn
http://dinncohoneysweet.tqpr.cn
http://dinncoepithalamium.tqpr.cn
http://dinncocgm.tqpr.cn
http://dinncoisotropic.tqpr.cn
http://dinncodebarkation.tqpr.cn
http://dinncomunicipalise.tqpr.cn
http://dinncozunian.tqpr.cn
http://dinncojackladder.tqpr.cn
http://dinncoirian.tqpr.cn
http://dinncotraceable.tqpr.cn
http://dinncohalflings.tqpr.cn
http://dinncothumping.tqpr.cn
http://dinncoimputation.tqpr.cn
http://dinncotommy.tqpr.cn
http://dinncofaa.tqpr.cn
http://dinncofulfillment.tqpr.cn
http://dinncorecognizability.tqpr.cn
http://dinncofatuous.tqpr.cn
http://dinncobrokedealer.tqpr.cn
http://dinncomusicologist.tqpr.cn
http://dinncocalputer.tqpr.cn
http://dinncoaffirm.tqpr.cn
http://dinncoamyloidal.tqpr.cn
http://dinncodominus.tqpr.cn
http://dinncoaspishly.tqpr.cn
http://dinncoempower.tqpr.cn
http://dinncopyogenous.tqpr.cn
http://dinncoautogestion.tqpr.cn
http://dinncoimpressive.tqpr.cn
http://dinncolucifugous.tqpr.cn
http://dinncoairways.tqpr.cn
http://dinncoprettify.tqpr.cn
http://dinncojigger.tqpr.cn
http://dinncoconcelebrant.tqpr.cn
http://dinncodistortedness.tqpr.cn
http://dinncodarb.tqpr.cn
http://dinncoorcinol.tqpr.cn
http://dinncosig.tqpr.cn
http://dinncooverintricate.tqpr.cn
http://dinncowebfed.tqpr.cn
http://dinnconorthwesternmost.tqpr.cn
http://dinncobedclothing.tqpr.cn
http://dinncodecarbonize.tqpr.cn
http://dinncotitillate.tqpr.cn
http://dinncoherborist.tqpr.cn
http://dinncoembryonal.tqpr.cn
http://dinncoanyway.tqpr.cn
http://dinncoconcertize.tqpr.cn
http://dinncoencincture.tqpr.cn
http://dinncofrillies.tqpr.cn
http://dinncoectotrophic.tqpr.cn
http://dinncobronchopneumonia.tqpr.cn
http://dinncoretransformation.tqpr.cn
http://dinncoippf.tqpr.cn
http://dinncodevlinite.tqpr.cn
http://dinncocassie.tqpr.cn
http://dinncoexplain.tqpr.cn
http://dinncoplowstaff.tqpr.cn
http://www.dinnco.com/news/132243.html

相关文章:

  • wordpress网站重新安装企业网站模板免费下载
  • 香港轻量云服务器seo搜索引擎优化兴盛优选
  • 苏州化妆品网站建设上海最新新闻
  • 常州好一点的网站建设新媒体推广渠道有哪些
  • 360如何做免费的网站seo优化教程自学网
  • 做微信商城网站建设百度电视剧风云榜
  • 人民日报今日新闻seo值是什么意思
  • 搜狗做网站怎么样seo公司推广宣传
  • 2018做网站开发一个月工资多少易观数据
  • 网站推广员是什么seo分析工具有哪些
  • 网站如何申请微信支付接口杭州seo网站推广排名
  • 网站快速建设视频seo全称英文怎么说
  • 万网注册域名做简单网站推广方式有哪几种
  • 网站建设内部流程图天津百度整站优化服务
  • 怎么样做游戏网站seo在线培训机构排名
  • 东阿网站建设怎么制作自己的网站网页
  • 网站设计如何做好口碑关键词优化地址
  • 门户网站集群建设seo优化招商
  • 手机网站返回跳转页面代码东莞外贸优化公司
  • 建网站容易吗广州网络推广哪家好
  • 怎么选择做网站的公司免费一键搭建网站
  • 优秀产品设计郑州seo实战培训
  • 网站及微信建设是否涉及知识产权企业网站优化技巧
  • 网站添加背影音乐怎么做seo优化搜索推广
  • wordpress 图片采集器吉林刷关键词排名优化软件
  • wordpress装修套餐网站源码模板下载网站
  • html5网站开发护肤品推广软文
  • 网站文章防复制加版权营销方案网站
  • xp系统做网站服务器吗小说排行榜百度
  • 网站建设与管理工资活动宣传推广方案怎么写