当前位置:网站首页>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
边栏推荐
猜你喜欢

Android金九银十的面试你准备的怎么样了?最新Android面试真题汇总助你备战

Create a linked list by head interpolation and output all elements
Qt | 设置部件大小 sizeHint、minimumSizeHint、sizePolicy、stretch factor

ciscn_ 2019_ n_ one
![[Fifth space 2019 finals]pwn5](/img/51/03e6078961a8eab991fa08bb178a7b.png)
[Fifth space 2019 finals]pwn5
![[第五空间2019 决赛]PWN5](/img/51/03e6078961a8eab991fa08bb178a7b.png)
[第五空间2019 决赛]PWN5

Esp8266 nodemcu - get real-time weather from Suning API

The most complete 2022 Android interview questions in history

bjdctf_2020_babystack
![[ssm] joint commissioning of front and rear console protocols ②](/img/ed/6a42e19f384fa0d4a039e52f5a95f4.png)
[ssm] joint commissioning of front and rear console protocols ②
随机推荐
DGS first acquaintance
y75.第四章 Prometheus大厂监控体系及实战 -- prometheus报警设置(六)
qiankun子应用package.json中的name成了默认路径
工具推荐-语雀
[computer three-level information security] access control model
[数组]NC95 数组中的最长连续子序列-较难
Chapter 7: test architecture elements
Sentinel链路方式流控失效解决
SQL语句实战学习
Error handling of DGS
Windows软件:如何安装Mysql5.7并配置环境变量
idea无法切换成中文
[for loop if conditional statement] summary
ubtun 更新源
ciscn_2019_n_8
Network security class assignment
JS Learning Notes - - the Underlying Implementation of Array Method
[Fifth space 2019 finals]pwn5
PushGateway+Prometheus+Grafana构建Flink实时监控
网上找客户经理办理基金开户安全吗??