当前位置:网站首页>About making a progress bar for software initialization for Qt
About making a progress bar for software initialization for Qt
2022-08-01 05:08:00 【The whimsical Yu Ruiyin】
为什么
Why make an initialization progress bar for the software?
A slightly larger software,Lots of pages and resources,Only initialize when all resources and pages are in use,Then a slightly larger page will be stuck when it is openedPPT.All pages are initialized when the software is just opened,It can solve the subsequent software freeze problem.But the software is all initialized when it is just opened,配合是openmp创建多个线程,Use multiple threads to quickly complete initialization work,The relevant page functions at this time cannot be too complicated,A progress bar that can indicate the progress of software initialization is the best choice.
说明
I don't have a window that needs to load a lot of resources for the time being,就是用Sleepfunction instead of its function,Implement its initialization function.
效果展示
程序
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QTimer>
namespace Ui {
class MainWindow;
}
class MainWindow : public QWidget
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = nullptr);
~MainWindow();
signals:
void ooo();
private slots:
void on_timerout();
void on_timerout2();
private:
Ui::MainWindow *ui;
QTimer timer;
};
#endif // MAINWINDOW_H
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <omp.h>
#include <QDebug>
#include <windows.h>
int count=0;
MainWindow::MainWindow(QWidget *parent) :
QWidget(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->progressBar->setRange(0,70);
setWindowFlags(Qt::FramelessWindowHint);//隐藏标题栏,remove taskbar,Put the window on top of all windows
this->setAttribute(Qt::WA_TranslucentBackground);
connect(&timer,&QTimer::timeout,this,&MainWindow::on_timerout2);
connect(this,&MainWindow::ooo,this,&MainWindow::on_timerout);
timer.start(20);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_timerout()
{
ui->progressBar->setValue(count);
if(count>=70)
close();
}
void MainWindow::on_timerout2()
{
timer.stop();
#pragma omp parallel for
for (int i = 1; i <= 70; i++)
{
Sleep(1000);
qDebug() << "Hello World! " << i <<" "<<count<< endl;
count++;
ooo();
}
qDebug()<<count<<endl;
}
UIThere is only one progress bar in the file
最后
初始化过程中openmp的forThe number of loops should not be too large,最大保持在50左右,Any higher progress bar will get stuck,出现一个黑框.
边栏推荐
猜你喜欢
力扣(LeetCode)212. 单词搜索 II(2022.07.31)
律师解读 | 枪炮还是玫瑰?从大厂之争谈元宇宙互操作性
[target detection] YOLOv7 theoretical introduction + practical test
MySQL-数据定义语言-DDLdatebase define language
(2022牛客多校四)H-Wall Builder II(思维)
typescript24 - type inference
Code Interview Guide for Programmers CD15 Generating an Array of Windowed Maximums
(2022 Nioke Duo School IV) H-Wall Builder II (Thinking)
SL-12/2过流继电器
typescript20-接口
随机推荐
typescript19-对象可选参数
pytorch、tensorflow对比学习—功能组件(优化器、评估指标、Module管理)
scheduleWithFixedDelay和scheduleAtFixedRate的区别
图片更新之后Glide加载依旧是原来的图片问题
Challenge 52 days to memorize Peppa Pig (Day 01)
牛客多校2022第四场A,H,K,N
WPF项目-按着键盘方向键,移动格子盒子效果
4D line-by-line analysis and implementation of Transformer, and German translation into English (3)
(2022 Niu Ke Duo School IV) N-Particle Arts (Thinking)
中国的机器人增长
Progressive Reconstruction of Visual Structure for Image Inpainting 论文笔记
Selenium:表单切换
SL-12/2过流继电器
2022/07/29 入职健海JustFE团队,我学到了高效开发(年中总结)
JWL-11/2-99.9A电流继电器
MySQL-DML language-database operation language-insert-update-delete-truncate
2022年超全的Android面经(附含面试题|进阶资料)
y83.第四章 Prometheus大厂监控体系及实战 -- prometheus告警机制进阶(十四)
pytroch、tensorflow对比学习—使用GPU训练模型
移动应用恶意攻击激增500% 三六零天御为APP免费构建安全屏障