当前位置:网站首页>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,出现一个黑框.
边栏推荐
- (2022 Niu Ke Duo School IV) K-NIO's Sword (Thinking)
- Logitech Mouse Experience Record
- 用控件当画笔获得bitmap代码记录
- 【云原生之kubernetes实战】kubernetes集群的检测工具——popeye
- HJS-DE1/2时间继电器
- 解决ffmpeg使用screen-capture-recorder录屏,有屏幕缩放的情况下录不全的问题
- JWL-11/2-99.9A电流继电器
- Li Chi's work and life summary in July 2022
- Dry goods!How to Construct SRv6-TE Performance Test Environment Using Instrumentation
- 万字逐行解析与实现Transformer,并进行德译英实战(一)
猜你喜欢
API Design Notes: The pimpl trick
Selenium:操作Cookie
DL-31/6电流继电器
Swastika line-by-line parsing and realization of the Transformer, and German translation practice (a)
USB3.0:VL817Q7-C0的LAYOUT指南(二)
MySQL-DML语言-数据库操作语言-insert-update-delete-truncate
Progressive Reconstruction of Visual Structure for Image Inpainting 论文笔记
(Codeforce 757) E. Bash Plays with Functions
typescript25-类型断言
typescript21 - Comparison of Interfaces and Type Aliases
随机推荐
数组问题之《下一个排列》、《旋转图像》以及二分查找之《搜索二维矩阵》
typescript27 - what about enumeration types
请问表格储存中用sql只能查询到主键列,ots sql非主键不支持吗?
MySQL Practice Summary -
MySQL-Data Definition Language-DDLdatebase define language
LeetCode 231. 2 的幂
SL-12/2过流继电器
typescript28-枚举类型的值以及数据枚举
备战金九银十,如何顺利通过互联网大厂Android的笔面试?
The difference between scheduleWithFixedDelay and scheduleAtFixedRate
剑指 Offer 68 - I. 二叉搜索树的最近公共祖先
Selenium:元素等待
HJS-DE1/2时间继电器
状态压缩dp
vim配置+ctag像source insight一样方便阅读代码
律师解读 | 枪炮还是玫瑰?从大厂之争谈元宇宙互操作性
Typescript22 - interface inheritance
state compressed dp
typescript22-接口继承
图片更新之后Glide加载依旧是原来的图片问题