解决一个Qt程序崩溃的问题

当Qt崩溃时,使用Qt Creator调试,也无法定位到是哪个地方除了问题。只发现日志报出一个Fatal。

复制代码
Fatal:  2023-11-05 00:16:26 [io\qprocess_win.cpp:826]  ASSERT: "pid" in file io\qprocess_win.cpp, line 826

触发的情况,就是使用QProcess同时启动多个进程时,主动退出进程导致的。

定位到代码的位置在:

cpp 复制代码
void zip7z::terminal()
{
    process.kill();
    process.waitForFinished();
}

这个 terminal 是在主线程被调用的。在process主动退出前,调用这个接口,就会卡死。

注释掉 process.waitForFinished(); 即可解决这个问题。怀疑是进程没有被kill掉,导致主线程一直阻塞,然后崩溃的。仅仅是怀疑,但我没有证据...

Qt官方文档对于这个接口的解释:

复制代码
Blocks until the process has finished and the finished() signal has been emitted, or until msecs milliseconds have passed.
Returns true if the process finished; otherwise returns false (if the operation timed out, if an error occurred, or if this QProcess is already finished).
This function can operate without an event loop. It is useful when writing non-GUI applications and when performing I/O operations in a non-GUI thread.
Warning: Calling this function from the main (GUI) thread might cause your user interface to freeze.
If msecs is -1, this function will not time out

总之,就是不要在主线程中使用这个接口,否则会导致UI卡主。

相关推荐
比昨天多敲两行19 分钟前
linux 线程概念与控制
java·开发语言·jvm
huaweichenai29 分钟前
php 根据每个类型的抽签范围实现抽签功能
开发语言·php
codeejun2 小时前
每日一Go-73、云原生成本优化 —— 资源限制 & 指标驱动扩容
开发语言·云原生·golang
就叫_这个吧2 小时前
Java注解、元注解、自定义注解定义及应用
java·开发语言·注解
Sam_Deep_Thinking3 小时前
聊聊Java中的of
java·开发语言·架构
小小de风呀5 小时前
de风——【从零开始学C++】(十一):list的基本使用和模拟实现
开发语言·c++·list
三行数学6 小时前
Matlab之父克利夫·莫勒尔逝世
开发语言·matlab
陌路206 小时前
C++高级进阶--夯实进阶基础(1)
开发语言·c++
梦想三三6 小时前
【PYthon词频统计与文本向量化】苏宁易购评论分析实战
开发语言·python
AI人工智能+电脑小能手6 小时前
【大白话说Java面试题 第93题】【Mysql篇】第23题:从查找速度来看,聚集索引和非聚集索引哪个更快?
java·开发语言·数据库·mysql·面试