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

相关推荐
技术砖家--Felix14 分钟前
Spring Boot入门篇:快速搭建你的第一个Spring Boot应用
java·开发语言·音视频
国服第二切图仔18 分钟前
Rust开发之使用Trait对象实现多态
开发语言·算法·rust
Yolo566Q21 分钟前
Python驱动的无人机生态三维建模与碳储/生物量/LULC估算全流程实战技术
开发语言·python·无人机
我不是程序猿儿40 分钟前
【C#】XtraMessageBox(DevExpress)与MessageBox(WinForms 标准库)的区别
开发语言·c#
含目的基因的质粒2 小时前
Python异常、模块、包
服务器·开发语言·python
千码君20163 小时前
Go语言:解决 “package xxx is not in std”的思路
开发语言·后端·golang
Ypuyu3 小时前
【GoLang】【框架学习】【GORM】4. 使用 BeforeUpdate hook 操作时,出现反射报错
开发语言·学习·golang
maizeman1263 小时前
用R语言生成指定品种与对照的一元回归直线(含置信区间)
开发语言·回归·r语言·置信区间·品种测试
脚踏实地的大梦想家4 小时前
【Go】P17 Go语言并发编程核心:深入理解 Goroutine (从入门到实战)
java·开发语言·golang
初学小白...4 小时前
线程同步机制及三大不安全案例
java·开发语言·jvm