当前位置:网站首页>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,出现一个黑框.
边栏推荐
- 25. Have you been asked these three common interview questions?
- 万字逐行解析与实现Transformer,并进行德译英实战(三)
- Code Interview Guide for Programmers CD15 Generating an Array of Windowed Maximums
- 请问shake数据库中为什么读取100个collection 后,直接就退出了,不继续读了呢?
- Power button (LeetCode) 212. The word search II (2022.07.31)
- 高数 | 【重积分】线面积分880例题
- typescript21 - Comparison of Interfaces and Type Aliases
- MySQL Practice Summary -
- PAT乙级 1002 写出这个数
- ModuleNotFoundError: No module named 'tensorflow.keras' error message solution
猜你喜欢

56:第五章:开发admin管理服务:9:开发【文件上传到,MongoDB的GridFS中,接口】;(把文件上传到GridFS的SOP)

律师解读 | 枪炮还是玫瑰?从大厂之争谈元宇宙互操作性

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

FFmpeg 搭建本地屏幕录制环境

(Codeforce 757) E. Bash Plays with Functions

Lawyer Interpretation | Guns or Roses?Talking about Metaverse Interoperability from the Battle of Big Manufacturers

pytorch、tensorflow对比学习—功能组件(激活函数、模型层、损失函数)

Robot_Framework:关键字

(2022 Niu Ke Duo School IV) K-NIO's Sword (Thinking)

typescript21 - Comparison of Interfaces and Type Aliases
随机推荐
Visual Studio提供的 Command Prompt 到底有啥用
请问表格储存中用sql只能查询到主键列,ots sql非主键不支持吗?
7月编程排行榜来啦!这次有何新变化?
Pyspark机器学习:向量及其常用操作
scheduleWithFixedDelay和scheduleAtFixedRate的区别
HJS-DE1/2时间继电器
typescript27-枚举类型呢
Power button (LeetCode) 212. The word search II (2022.07.31)
Selenium:元素等待
UE4 rays flashed from mouse position detection
mysql中解决存储过程表名通过变量传递的方法
华为Android开发面试后得出的面试秘诀
typescript28 - value of enumeration type and data enumeration
[target detection] YOLOv7 theoretical introduction + practical test
MySQL-DML language-database operation language-insert-update-delete-truncate
LeetCode 27. 移除元素
(2022牛客多校四)K-NIO‘s Sword(思维)
UE4 从鼠标位置射出射线检测
Swastika line-by-line parsing and realization of the Transformer, and German translation practice (2)
WPF项目-按着键盘方向键,移动格子盒子效果