网站建设一般用什么语言,公司网站建设东莞,flash 可以做网站吗,百度网盟推广网站背景#xff1a;最近在写一个删除90天数据显示进度的功能#xff0c;实现思路是#xff1a;通过信号槽捕获当前进度值实现。 备注#xff1a;点击start按钮#xff0c;开始更新进度条#xff0c;直到100#xff08;每隔1s进行更新#xff09;举个栗子#xff1a;
1、… 背景最近在写一个删除90天数据显示进度的功能实现思路是通过信号槽捕获当前进度值实现。 备注点击start按钮开始更新进度条直到100每隔1s进行更新举个栗子
1、mainwindow.cpp
#include mainwindow.h
#include ui_mainwindow.h
#includeQThreadMainWindow::MainWindow(QWidget *parent): QMainWindow(parent), ui(new Ui::MainWindow)
{ui-setupUi(this);connect(ui-pushButton,QPushButton::clicked,this,MainWindow::close);connect(ui-pushButton1,QPushButton::clicked,this,MainWindow::on_startProcess);void (MyThread::*rmsgSignal)(int) MyThread::msgSignal;connect(thread,rmsgSignal,this,MainWindow::on_setProcess);ui-progressBar-setRange(0,100);}MainWindow::~MainWindow()
{delete ui;
}//开启线程
void MainWindow::on_startProcess(){thread.start();}//设置进度条参数
void MainWindow::on_setProcess(int v){ui-progressBar-setValue(v);
}2、mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include mythread.h#include QMainWindowQT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACEclass MainWindow : public QMainWindow
{Q_OBJECTpublic:MainWindow(QWidget *parent nullptr);~MainWindow();MyThread thread;void on_startProcess();void on_setProcess(int v);private:Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H3、mythread.cpp
#include mythread.hMyThread::MyThread()
{}//重写run方法
void MyThread::run(){for(int i 1;i100;i){QThread::msleep(1000);emit msgSignal(i);}
}4、MyThread.h
#ifndef MYTHREAD_H
#define MYTHREAD_H
#include QThreadclass MyThread: public QThread{Q_OBJECT
public:MyThread();void run() override;signals:void msgSignal(int a);
};#endif // MYTHREAD_H5、main.cpp
#include mainwindow.h#include QApplicationint main(int argc, char *argv[])
{QApplication a(argc, argv);MainWindow w;w.show();return a.exec();
}6、mainwindow.ui
?xml version1.0 encodingUTF-8?
ui version4.0classMainWindow/classwidget classQMainWindow nameMainWindowproperty namegeometryrectx0/xy0/ywidth800/widthheight600/height/rect/propertyproperty namewindowTitlestringMainWindow/string/propertywidget classQWidget namecentralwidgetwidget classQWidget nameverticalLayoutWidgetproperty namegeometryrectx320/xy140/ywidth160/widthheight80/height/rect/propertylayout classQVBoxLayout nameverticalLayoutitemwidget classQPushButton namepushButtonproperty nametextstringclose/string/property/widget/itemitemwidget classQPushButton namepushButton1property nametextstringstart/string/property/widget/itemitemwidget classQProgressBar nameprogressBarproperty namevaluenumber0/number/propertyproperty nameformatstring%v%/string/property/widget/item/layout/widget/widgetwidget classQMenuBar namemenubarproperty namegeometryrectx0/xy0/ywidth800/widthheight23/height/rect/property/widgetwidget classQStatusBar namestatusbar//widgetresources/connections/
/ui7、结果 注视频为测试结果仅录制部分作为参考 ProgressBar