当前位置:网站首页>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,出现一个黑框.
边栏推荐
- Pyspark Machine Learning: Vectors and Common Operations
- 【目标检测】YOLOv7理论简介+实践测试
- LeetCode 231. 2 的幂
- (2022牛客多校四)A-Task Computing (排序+动态规划)
- API Design Notes: The pimpl trick
- PaddleX部署推理模型和GUI界面测试结果不一致的解决方法
- scheduleWithFixedDelay和scheduleAtFixedRate的区别
- 关于给Qt做一个软件初始化的进度条
- 冲刺金九银十,Android开发面试(内含面试资料|面试题|源码)
- safari浏览器怎么导入书签
猜你喜欢

Typescript20 - interface

typescript24-类型推论

state compressed dp

The difference between scheduleWithFixedDelay and scheduleAtFixedRate

Robot_Framework:断言

mysql中解决存储过程表名通过变量传递的方法

typescript26-字面量类型

「以云为核,无感极速」顶象第五代验证码

typescript21 - Comparison of Interfaces and Type Aliases

II. Binary tree to Offer 68 - recent common ancestor
随机推荐
Typescript20 - interface
typescript26-字面量类型
pytroch、tensorflow对比学习—专栏介绍
万字逐行解析与实现Transformer,并进行德译英实战(二)
API设计笔记:pimpl技巧
PAT乙级 1002 写出这个数
[MySQL] 多表查询
ModuleNotFoundError: No module named ‘tensorflow.keras‘报错信息的解决方法
Selenium:简介
2022/07/29 入职健海JustFE团队,我学到了高效开发(年中总结)
Selenium:鼠标、键盘事件
Seleniu:元素常用操作
LeetCode 1189. “气球” 的最大数量
初识shell脚本
请求/响应拦截器写法
冲刺金九银十,Android开发面试(内含面试资料|面试题|源码)
pytorch、tensorflow对比学习—计算图和微分机制
25. 这三道常见的面试题,你有被问过吗?
Swastika line-by-line parsing and realization of the Transformer, and German translation practice (a)
High Numbers | 【Re-integration】Line Area Score 880 Examples