当前位置:网站首页>关于给Qt做一个软件初始化的进度条
关于给Qt做一个软件初始化的进度条
2022-08-01 04:59:00 【异想天开的余瑞银】
为什么
为什么要给软件做一个初始化的进度条?
一个稍微大型一点的软件,页面和资源众多,如果所有的资源和页面都是要用的时候才初始化,那么稍微大一点的页面打开时就会卡得像PPT。在软件刚刚打开时对所有的页面进行初始化,就可以解决后续的软件卡顿的问题。但是软件刚打开时就全部初始化,配合是openmp创建多个线程,使用多个线程快速完成初始化的工作,此时的相关页面功能不能太过于复杂,可以表示软件初始化进度的进度条就是最好的选择。
说明
本人这里暂时没有需要加载大量资源的窗口,就是用Sleep函数代替其功能,实现其初始化的功能。
效果展示
程序
#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);//隐藏标题栏,去除任务栏,将窗口位于所有窗口最顶层
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;
}
UI文件中只有一个进度条
最后
初始化过程中openmp的for循环的数值不要太大,最大保持在50左右,再高进度条就会卡住,出现一个黑框。
边栏推荐
- PMP 项目质量管理
- (2022牛客多校四)H-Wall Builder II(思维)
- 数组问题之《两数之和》以及《三数之和 》
- 基于Arduino制作非接触式测温仪
- Error: AttributeError: module 'matplotlib' has no attribute 'figure'
- August 22 Promotion Ambassador Extra Reward Rules
- Mysql基础篇(约束)
- UE4 制作遇到的问题
- Risk strategy important steps of tuning method
- 报错:AttributeError: module ‘matplotlib’ has no attribute ‘figure’
猜你喜欢
PAT乙级 1002 写出这个数
Excel record of integer programming optimization model to solve the problem
typescript24-类型推论
罗技鼠标体验记录
7月编程排行榜来啦!这次有何新变化?
How to promote new products online?
出现Command ‘vim‘ is available in the following places,vim: command not found等解决方法
[target detection] YOLOv7 theoretical introduction + practical test
数组问题之《下一个排列》、《旋转图像》以及二分查找之《搜索二维矩阵》
I met a shell script
随机推荐
Pyspark机器学习:向量及其常用操作
阿叶的目标
请问shake数据库中为什么读取100个collection 后,直接就退出了,不继续读了呢?
Mysql基础篇(约束)
4D line-by-line analysis and implementation of Transformer, and German translation into English (3)
力扣(LeetCode)212. 单词搜索 II(2022.07.31)
UE4 rays flashed from mouse position detection
(Codeforce 757)E. Bash Plays with Functions(积性函数)
56:第五章:开发admin管理服务:9:开发【文件上传到,MongoDB的GridFS中,接口】;(把文件上传到GridFS的SOP)
项目风险管理必备内容总结
MySQL-数据操作-分组查询-连接查询-子查询-分页查询-联合查询
PMP 项目质量管理
mysql中解决存储过程表名通过变量传递的方法
y83. Chapter 4 Prometheus Factory Monitoring System and Actual Combat -- Advanced Prometheus Alarm Mechanism (14)
pytorch、tensorflow对比学习—计算图和微分机制
PMP 相关方管理必背总结
typescript28 - value of enumeration type and data enumeration
微软 Win10 照片磁贴后的又一“刺客”,谷歌 Chrome 浏览器将在新标签页展示用户照片
The Flow Of Percona Toolkit pt-table-checksum
「以云为核,无感极速」顶象第五代验证码