当前位置:网站首页>关于给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左右,再高进度条就会卡住,出现一个黑框。
边栏推荐
- 一个往年的朋友
- The Flow Of Percona Toolkit pt-table-checksum
- UE4 制作遇到的问题
- The method of solving stored procedure table name passing through variable in mysql
- 基于ProXmoX VE的虚拟化家庭服务器(篇一)—ProXmoX VE 安装及基础配置
- LeetCode 231. 2 的幂
- Excuse me, only primary key columns can be queried using sql in table storage. Does ots sql not support non-primary keys?
- 在沈自所的半年总结
- 数据比对功能调研总结
- y83.第四章 Prometheus大厂监控体系及实战 -- prometheus告警机制进阶(十四)
猜你喜欢

C# | 使用Json序列化对象时忽略只读的属性

typescript27-枚举类型呢

II. Binary tree to Offer 68 - recent common ancestor

typescript21-接口和类型别名的对比

USB3.0:VL817Q7-C0的LAYOUT指南(二)

Risk strategy important steps of tuning method

剑指 Offer 68 - II. 二叉树的最近公共祖先

(2022牛客多校四)H-Wall Builder II(思维)

【愚公系列】2022年07月 Go教学课程 023-Go容器之列表

Lawyer Interpretation | Guns or Roses?Talking about Metaverse Interoperability from the Battle of Big Manufacturers
随机推荐
万字逐行解析与实现Transformer,并进行德译英实战(二)
Dry goods!How to Construct SRv6-TE Performance Test Environment Using Instrumentation
The Principle Of Percona Toolkit Nibble Algorithm
数组问题之《下一个排列》、《旋转图像》以及二分查找之《搜索二维矩阵》
API设计笔记:pimpl技巧
August 22 Promotion Ambassador Extra Reward Rules
(2022 Niu Ke Duo School IV) K-NIO's Sword (Thinking)
PMP 80个输入输出总结
认真对待每一个时刻
state compressed dp
pytorch、tensorflow对比学习—张量
万字逐行解析与实现Transformer,并进行德译英实战(三)
Pyspark Machine Learning: Vectors and Common Operations
pytroch、tensorflow对比学习—搭建模型范式(构建模型方法、训练模型范式)
剑指 Offer 68 - I. 二叉搜索树的最近公共祖先
怀念故乡的面条
(2022牛客多校四)A-Task Computing (排序+动态规划)
剑指 Offer 68 - II. 二叉树的最近公共祖先
typescript24-类型推论
请问shake数据库中为什么读取100个collection 后,直接就退出了,不继续读了呢?