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

相关推荐
稻草人想看远方7 分钟前
GC垃圾回收
java·开发语言·jvm
胡萝卜的兔25 分钟前
go 日志的分装和使用 Zap + lumberjack
开发语言·后端·golang
浪扼飞舟29 分钟前
c#基础(一)
开发语言·c#
百锦再1 小时前
在 CentOS 系统上实现定时执行 Python 邮件发送任务
java·linux·开发语言·人工智能·python·centos·pygame
何似在人间5752 小时前
Go语言快速入门教程(JAVA转go)——1 概述
java·开发语言·golang
边疆.2 小时前
【C++】继承详解
开发语言·c++·继承
lxh01132 小时前
LRU 缓存
开发语言·前端·javascript
空山新雨(大队长)3 小时前
Java第五课:输入输出
java·开发语言
wow_DG3 小时前
【Vue2 ✨】Vue2 入门之旅 · 进阶篇(二):虚拟 DOM 与 Diff 算法
开发语言·javascript·vue.js·算法·前端框架
sali-tec4 小时前
C# 基于halcon的视觉工作流-章32-线线测量
开发语言·人工智能·算法·计算机视觉·c#