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

相关推荐
麻辣璐璐20 小时前
EditText属性运用之适配RTL语言和LTR语言的输入习惯
android·xml·java·开发语言·安卓
2301_8035545220 小时前
C++ 并发核心:std::promise、std::future、std::async 超详细全解
开发语言·c++
俺不要写代码20 小时前
线程启动、结束,创建线程多法、join,detach,线程的移动语义
服务器·开发语言·网络·c++
雾岛听蓝20 小时前
Qt Widget控件属性详解
开发语言·经验分享·笔记·qt
好家伙VCC20 小时前
# 发散创新:用 Rust实现高性能物理引擎的底层架构设计与实战在游戏开发、虚拟仿真和机器人控
java·开发语言·python·rust·机器人
boonya21 小时前
一文读懂MCP:AI连接万物的“USB-C接口”
c语言·开发语言·人工智能
liliangcsdn21 小时前
多轮对话长上下文-向量检索和混合召回示例
开发语言·数据库·人工智能·python
leoZ23121 小时前
金仓老旧项目改造-10
开发语言·前端·人工智能·python·金仓
故事和你9121 小时前
洛谷-数据结构1-1-线性表2
开发语言·数据结构·算法·动态规划·图论
小徐不徐说21 小时前
面试C++易错点总结
开发语言·c++·面试·职场和发展·程序设计·工作