当前位置:网站首页>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,出现一个黑框.
边栏推荐
猜你喜欢
备战金九银十,如何顺利通过互联网大厂Android的笔面试?
UE4 从鼠标位置射出射线检测
typescript25-类型断言
可持久化线段树
MySQL-DML语言-数据库操作语言-insert-update-delete-truncate
「以云为核,无感极速」顶象第五代验证码
The method of solving stored procedure table name passing through variable in mysql
6-23漏洞利用-postgresql代码执行利用
typescript25 - type assertion
剑指 Offer 68 - II. 二叉树的最近公共祖先
随机推荐
Typescript20 - interface
typescript21 - Comparison of Interfaces and Type Aliases
风险策略调优中重要的三步分析法
可持久化线段树
pytroch、tensorflow对比学习—搭建模型范式(构建模型方法、训练模型范式)
(Codeforce 757) E. Bash Plays with Functions
这里有110+公开的专业数据集
High Numbers | 【Re-integration】Line Area Score 880 Examples
[target detection] YOLOv7 theoretical introduction + practical test
Robot_Framework:常用内置关键字
Selenium:元素判断
文件的异步读写
Selenium:元素等待
pytorch、tensorflow对比学习—功能组件(激活函数、模型层、损失函数)
The difference between scheduleWithFixedDelay and scheduleAtFixedRate
UE4 rays flashed from mouse position detection
Selenium:表单切换
Swastika line-by-line parsing and realization of the Transformer, and German translation practice (a)
PAT乙级 1001 害死人不偿命的(3n+1)猜想
Visual Studio提供的 Command Prompt 到底有啥用