当前位置:网站首页>Qt创建窗口被阻塞不能及时显示的问题
Qt创建窗口被阻塞不能及时显示的问题
2022-07-23 23:36:00 【百口可乐__】
在函数中动态创建窗口并显示时,如果后面有密集计算的代码,或者延时函数,会导致创建的窗口不能及时显示而被阻塞
如
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会在后面的for循环结束后才能得到显示,
对此的解决办法就是异步运行计算密集的代码,让他不能阻塞窗口的显示
将代码写入函数Calc
void Calc(){
for(i = 0;i<99;i++){
...
}
}
包含异步运行需要的头文件
#include <QtConcurrent/QtConcurrent>
#include <QFuture>
原来的代码改为
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);
}
之后窗口就可以马上显示了
边栏推荐
- Ubtun update source
- 第五章、实现Web适配器
- Solidity-delegateCall插槽冲突分析与解决
- [array] longest continuous subsequence in nc95 array - difficult
- Create a linked list by head interpolation and output all elements
- Redis管道技术/分区
- [tensorflow] check whether tensorflow GPU is available
- 史上最全的2022年版Android面试题
- ciscn_2019_n_1
- 第七章、测试架构元素
猜你喜欢

在openEuler社区开源的Embedded SIG,来聊聊它的多 OS 混合部署框架

How to migrate databases in the flask framework

strncat() strncmp()

AutoCAD advanced operation

Structured Streaming 编程模型(Input Table、Result Table、Output Mode...)

Mobile, telecom and Unicom: fancy solution of 5g to B

BGP选路,MPLS

Stm32mp1 M4 bare metal cubeide Development Guide Chapter 6 stm32cube firmware package
![[audio and video technology] video quality evaluation MSU vqmt & Netflix vmaf](/img/1c/bc71ba1eb3723cdd80501f2b0ad5ce.png)
[audio and video technology] video quality evaluation MSU vqmt & Netflix vmaf

jarvisoj_level2
随机推荐
PHP(2)
jarvisoj_level2
Interviewer: if the order is not paid within 30 minutes after it is generated, it will be automatically cancelled. How to realize it?
Strncat () strncmp ()
ubtun 更新源
USB to can device in nucleic acid extractor high performance USB interface can card
PHP(2)
Application of merging and sorting thought
ciscn_ 2019_ n_ one
Structured Streaming 编程模型(Input Table、Result Table、Output Mode...)
DDD思维架构学习
Sql156 average completion rate of each video
Go language multiple return values and return error types
Network security class assignment
ciscn_2019_c_1
Detailed explanation of pseudo instructions in assembly language (with examples)
C # introductory series (XXVIII) -- query syntax of LINQ
头插法创建链表并输出所有元素
第三章、组织代码
Redis集群搭建(Cluster 集群模式,分片集群)