解决一个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卡主。

相关推荐
瑾修18 分钟前
golang查找cpu过高的函数
开发语言·后端·golang
kkkAloha23 分钟前
JS笔记汇总
开发语言·javascript·笔记
LawrenceLan7 小时前
Flutter 零基础入门(十一):空安全(Null Safety)基础
开发语言·flutter·dart
txinyu的博客7 小时前
解析业务层的key冲突问题
开发语言·c++·分布式
码不停蹄Zzz7 小时前
C语言第1章
c语言·开发语言
行者968 小时前
Flutter跨平台开发在OpenHarmony上的评分组件实现与优化
开发语言·flutter·harmonyos·鸿蒙
阿蒙Amon8 小时前
C#每日面试题-Array和ArrayList的区别
java·开发语言·c#
SmartRadio8 小时前
ESP32添加修改蓝牙名称和获取蓝牙连接状态的AT命令-完整UART BLE服务功能后的完整`main.c`代码
c语言·开发语言·c++·esp32·ble
且去填词8 小时前
Go 语言的“反叛”——为什么少即是多?
开发语言·后端·面试·go
知乎的哥廷根数学学派9 小时前
基于生成对抗U-Net混合架构的隧道衬砌缺陷地质雷达数据智能反演与成像方法(以模拟信号为例,Pytorch)
开发语言·人工智能·pytorch·python·深度学习·机器学习