当前位置:网站首页>The QT creation window is blocked and cannot be displayed in time
The QT creation window is blocked and cannot be displayed in time
2022-07-23 23:43:00 【Pepsi__】
When the window is dynamically created and displayed in the function , If there is intensive computing code behind , Or delay function , It will cause the created window to be blocked because it cannot be displayed in time
Such as
m_widget = new QWidget(get_handle());
m_widget->resize (get_handle()->width(), get_handle()->height());
m_widget->move (0,0);
m_widget->setStyleSheet("background-color:rgba(0, 0, 0,80%);");
m_widget->show();
for(i = 0;i<99;i++){
...
}
m_widget It'll be in the back for Only after the cycle ends can it be displayed ,
The solution is to run compute intensive code asynchronously , Let him not block the display of the window
Write code to function Calc
void Calc(){
for(i = 0;i<99;i++){
...
}
}
Contains the header file required for asynchronous operation
#include <QtConcurrent/QtConcurrent>
#include <QFuture>
The original code is changed to
m_widget = new QWidget(get_handle());
m_widget->resize (get_handle()->width(), get_handle()->height());
m_widget->move (0,0);
m_widget->setStyleSheet("background-color:rgba(0, 0, 0,80%);");
m_widget->show();
QFuture<void> future = QtConcurrent::run(this, &MainWindow::Calc);
while(!future.isFinished());
{
QApplication::processEvents(QEventLoop::AllEvents,100);
}
Then the window can be displayed immediately
边栏推荐
猜你喜欢

Software architecture

The most complete 2022 Android interview questions in history
![[redis] redis installation and client redis cli use (batch operation)](/img/d7/7500e99bc3cf172f895a47aec0b44c.png)
[redis] redis installation and client redis cli use (batch operation)

Navicat15 download and installation

PHP(2)

No wonder the application effect of ERP in domestic enterprises is generally not ideal
![[ssm] joint commissioning of front and rear console protocols ②](/img/ed/6a42e19f384fa0d4a039e52f5a95f4.png)
[ssm] joint commissioning of front and rear console protocols ②

jarvisoj_ level2
![[OGeek2019]babyrop](/img/7a/18e8b985629488346e596cdf2a215c.png)
[OGeek2019]babyrop

Baidu editor uploads pictures and sets custom directories
随机推荐
Federation of DGS
BGP基础实验
PushGateway+Prometheus+Grafana构建Flink实时监控
bjdctf_ 2020_ babystack
[tensorflow] check whether tensorflow GPU is available
Chapter 7: test architecture elements
【细节】radio 标签 ,更换 默认选中的背景色
pwn1_sctf_2016
虚拟机导入iso后 Operating System not found 解决方法
Solo article body contains & lt; & gt; Labels affect page styles
工具推荐-语雀
cannot meet the needs of the people? How can programmers take private jobs to effectively increase their income?
JS convert numbers to uppercase
Analysis and resolution of slot conflict in solid delegatecall
Arrayslist and sequence table -- Simulation Implementation
怎么开户买收益6%的理财产品呢?
DGS file upload
为什么大多数人都认为编程很难?
solo 文章标题会过滤掉部分标签
ciscn_2019_n_8