多进程使用一个进度条,两个进程使用一个进度条,进度条槽函数设置成static 静态 函数
client_page.h
class client_page : public QMainWindow
{
Q_OBJECT
public:
client_page(QWidget* parent = nullptr);
~client_page();
public:
Ui::client_pageClass ui;
public slots:
static void show_progress_bar(int value_ );
static void show_pro_bar(int dpro);
public:
static uint32_t total_size_;
client_page* self_() { return m_self; }
private:
static int max_value_ ;
static std::mutex mutex;
static std::deque<int> write_deq;
static client_page* m_self;
};
client_page.cpp
uint32_t client_page::total_size_;
int client_page::max_value_;
std::mutex client_page::mutex;
std::deque<int> client_page::write_deq;
client_page* client_page::m_self = nullptr;
client_page::client_page(QWidget* parent)
: QMainWindow(parent)
, io_pool_(10)
{
ui.setupUi(this);
m_self = this;
ui.pro_bar->setOrientation(Qt::Horizontal);
ui.pro_bar->setMinimum(0);
ui.pro_bar->setMaximum(100);
connect(ui.add_upload,SIGNAL(clicked(bool)),this,SLOT(show_progress_bar(int)));
}
void client_page::show_progress_bar_max(int maxvalue_)
{
max_value_ = maxvalue_;
}
void client_page::show_progress_bar(int value_)
{
total_size_ += value_;
double dpro = (total_size_ * 100.00) / max_value_;
show_pro_bar(dpro);
}
void client_page::show_pro_bar(int dpro)
{
m_self->ui.pro_bar->setValue(dpro);
m_self->ui.pro_bar->update();
}