当前位置:网站首页>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,出现一个黑框.
边栏推荐
- ModuleNotFoundError: No module named ‘tensorflow.keras‘报错信息的解决方法
- 7 行代码搞崩溃 B 站,原因令人唏嘘!
- Selenium:上传、下载文件
- Lawyer Interpretation | Guns or Roses?Talking about Metaverse Interoperability from the Battle of Big Manufacturers
- USB3.0:VL817Q7-C0的LAYOUT指南(三)
- Immutable
- Selenium:弹窗处理
- Selenium:元素定位
- 解决ffmpeg使用screen-capture-recorder录屏,有屏幕缩放的情况下录不全的问题
- 中国的机器人增长
猜你喜欢
随机推荐
HJS-DE1/2时间继电器
USB3.0:VL817Q7-C0的LAYOUT指南(三)
罗技鼠标体验记录
UE4 rays flashed from mouse position detection
USB3.0:VL817Q7-C0的LAYOUT指南(二)
风险策略调优中重要的三步分析法
UE4 制作遇到的问题
Excel做题记录——整数规划优化模型
DL-31/6电流继电器
(2022牛客多校四)K-NIO‘s Sword(思维)
Risk strategy important steps of tuning method
typescript25 - type assertion
4D line-by-line analysis and implementation of Transformer, and German translation into English (3)
Selenium:鼠标、键盘事件
PAT乙级 1002 写出这个数
万字逐行解析与实现Transformer,并进行德译英实战(一)
ModuleNotFoundError: No module named 'tensorflow.keras' error message solution
MySQL Practice Summary -
Selenium:操作Cookie
Selenium:弹窗处理
![[target detection] YOLOv7 theoretical introduction + practical test](/img/ff/a83acbf9dd5cc2f907f3538d287842.png)








