Qtwebengine进程在应用程序关闭后不会关闭
Qtwebengineprocess is not closed after application closing
我有一个使用Qt WebEngine的应用程序。但是我发现在关闭我的应用程序或崩溃后,"Qtwebengineprocess"仍然保持打开状态。我的应用程序太大,无法在此处显示,但这里有一个小示例,也说明了问题:
#include <QApplication>
#include <QWebEngineView>
#include <QProcess>
#include <QTimer>
int main(int argc, char **argv)
{
QApplication app(argc, argv);
QWebEngineView* viewer = new QWebEngineView(NULL);
viewer->show();
viewer->load(QUrl("https://www.telegraph.co.uk/content/dam/Pets/spark/royal-canin/tabby-kitten-small.jpg?imwidth=1400"));
QTimer::singleShot(2000, []() {
exit(-1);
});
app.exec();
delete viewer;
return 0;
}
我忘了设置什么东西吗?或者这是一个Qt错误?提前谢谢。
更新:Qt 5.11, Win10
我找到了实际的问题和解决方案 - 在这里.这是Qt 5.11错误,它准确地描述了这个问题。
其中一条评论有对我有用的解决方案:
When running with QCoreApplication::setAttribute(Qt::AA_UseOpenGLES);
at the top of the main() function, I'm observing that the qtwebengine process closes correctly,
both when stopping the debugger and when the release exe crashes.
只是在创建我的qApp
之前添加了该行,没有看到任何崩溃。当然,这在Qt上使用ANGLE与动态GPU有好处也有缺点,更多细节在这里。
这似乎是 PyQt 5.11 及更高版本中的错误。重新安装操作系统并安装最新版本的 PyQt (5.11.3) 后,我遇到了这个问题和其他问题,QWebEngineView 无法在布局中正确调整大小。降级到 PyQt 5.10.1,一切再次正常运行。如果使用 Python,只需运行:
pip uninstall PyQt5
pip install PyQt5==5.10.1
参考这篇文章,当exit()
在main()
中被调用时,不会为本地范围的对象调用析构函数!exit()
不会返回。
放置在app.exec()
之后的任何代码(在您的情况下delete viewer;
),只有在主事件循环退出/退出并返回给调用者后才会执行, 您的计时器正在从主循环中调用 (stdlib)exit()
,这意味着: 您正在退出执行而不返回调用者, 并且,放置在app.exec()
之后的任何代码都不会被执行, 如果您希望代码正常运行并执行delete viewer;
,那么计时器应该退出主事件循环,因此您需要调用app.quit()
或app.exit(-1)
。
- 如何保护非托管应用程序中的字符串不受进程转储的影响
- 在 Windows/C++ 上使用多进程应用程序的高精度定时操作
- 从Visual Studio 2017运行MPI应用程序,每个进程在不同的cmd窗口中
- Qtwebengine进程在应用程序关闭后不会关闭
- 与 Python 中子进程中的另一个应用程序的交互式会话
- Electron应用程序和Win32本机桌面应用程序之间的进程间通信
- 如何在没有窗口类的情况下编写QT系统托盘应用程序,并将其与另一个进程集成
- 无法从C++应用程序中正确生成Raspberry Pi相机应用程序作为子进程
- Qt GUI应用程序在与GUI交互时停止实时进程
- 从 32 位应用程序挂接 64 位进程
- 从 MFC 应用程序启动 Java 时,在 MFC 应用程序中显示等待光标,直到它完成其进程
- 关闭Qt控制台应用程序会终止exec()调用中的进程,并且无法从main()扩展到范围
- 多个应用程序访问的单个进程
- 与多线程一起登录多进程应用程序
- 使用Windows中另一个进程的事件循环向Qt应用程序发送退出消息
- 是否可以从外部进程注入和执行应用程序
- GDB/DDD:使用多进程应用程序 C/C++调试共享库
- 多线程和多进程应用程序的锁定机制之间有什么区别
- 如何计算Linux中多进程应用程序的CPU使用率
- 进程(应用程序)的并行实例数