Qt-Creator progressBar进度条(进度栏)的制作

 

Qt-Creator progressBar进度条(进度栏)的制作_第1张图片

 


//Widget.h

#ifndef WIDGET_H
#define WIDGET_H

#include 
#include 
namespace Ui {
class Widget;
}

class Widget : public QWidget
{
    Q_OBJECT

public:
    explicit Widget(QWidget *parent = 0);
    ~Widget();
private slots:
    void doProcessStart(bool);
    void doProcessEnd(bool);
    void doProcesstTimeOut();


private:
    Ui::Widget *ui;
    QTimer *myTimer;
    void Init();
    int num;

};

#endif // WIDGET_H

 

//widget.cpp
#include "widget.h"
#include "ui_widget.h"
#include 
Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);
    Init();
}

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

 void Widget::Init()
{
    num=0;
    connect(ui->btn_start,SIGNAL(clicked(bool)),this,SLOT(doProcessStart(bool)));
    connect(ui->btn_end,SIGNAL(clicked(bool)),this,SLOT(doProcessEnd(bool)));
    myTimer=new QTimer(this);
    connect(myTimer,SIGNAL(timeout()),this,SLOT(doProcesstTimeOut()));
}
void Widget::doProcessStart(bool)
{
    qDebug()<<"start"<start(100);
}
void Widget::doProcessEnd(bool)
{
    qDebug()<<"end"<stop();
}
void Widget::doProcesstTimeOut()
{
    qDebug()<<"TimeOut"<100)
    {
        num=0;
    }
    ui->progressBar->setValue(num);
}

 

//main.cpp
#include "widget.h"
#include 

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    Widget w;
    w.show();

    return a.exec();
}

 

 

你可能感兴趣的:(Qt开发)