QWebEngineView::renderProcessTermminate 信号在 QT C++ 中不起作用;

发布于 2025-01-16 23:06:27 字数 917 浏览 1 评论 0原文

我正在尝试连接 qt c++ 中的信号和插槽。我想要实现的是,当浏览器完成渲染页面时,我希望它发出信号并在我的插槽中接收它。我最初是为 urlChanged() 信号编写的,它工作正常,但是当我将其更改为 renderProcessTermulated 时,它不会输出槽函数中的语句。

以下是声明槽的 MyClass.h 文件的片段:

private slots:
        void onRenderProcessTerminated(QWebEnginePage::RenderProcessTerminationStatus terminationStatus, int exitCode);

以下是 MyClass.cpp 文件的构造函数的片段,其中信号和槽是连接:

connect(ui->webEngineView, &QWebEngineView::renderProcessTerminated, this, &MyClass::onRenderProcessTerminated);

以下是来自 MyClass.cpp 的槽函数 onRenderProcessTermulated (cout 是我创建的用于在 Web 引擎视图中输出消息的函数,并且工作正常):

void MyClass::onRenderProcessTerminated(QWebEnginePage::RenderProcessTerminationStatus terminationStatus, int exitCode) {
    cout("INSIDE RENDER PROCESS TERMINATED");
}

I am trying to connect a signal and slot in qt c++. What I want to achieve is that when the browser finishes rendering the page I want it to emit the signal and receive it in my slot. I initially wrote it for urlChanged() signal and it works fine but when I change it to renderProcessTerminated, it doesnt output the statements in the slot function.

The following is a snippet of the MyClass.h file where the slot is declared:

private slots:
        void onRenderProcessTerminated(QWebEnginePage::RenderProcessTerminationStatus terminationStatus, int exitCode);

The following is a snippet from the constructor of MyClass.cpp file where the signal and slot are connected:

connect(ui->webEngineView, &QWebEngineView::renderProcessTerminated, this, &MyClass::onRenderProcessTerminated);

The following is the slot function onRenderProcessTerminated from MyClass.cpp (cout is a function I created to output messages in the web engine view and works fine):

void MyClass::onRenderProcessTerminated(QWebEnginePage::RenderProcessTerminationStatus terminationStatus, int exitCode) {
    cout("INSIDE RENDER PROCESS TERMINATED");
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦醒灬来后我 2025-01-23 23:06:27

我想要实现的是,当浏览器完成渲染页面时我希望它发出信号

RenderProcessTermulated 并不意味着“完成渲染页面”。这意味着操作系统用于渲染的进程异常终止。例如,当渲染器崩溃时,就会发生这种情况。 Qt文档明确指出:

当渲染进程以非零退出状态终止时,会发出此信号。 terminationStatus 是进程的终止状态,exitCode 是进程终止的状态代码。

在英语中,您要查找的动词是完成而不是终止。前者意味着后者:当一个进程完成时,它就终止了。但相反的情况是不必要的:进程很可能在完成其任务之前终止,例如,如果它崩溃,或者在父进程退出时终止,等等。而且:RenderProcess 不会意思是“渲染某些东西的任务”。它的字面意思是“执行渲染的操作系统进程”。只要您有任何活动的网络视图,该进程通常就必须保持活动状态。

我能看到的唯一接近您想要的信号是 QWebEngineView::loadFinished(bool ok) 。尝试一下。

另外,为了获得更精细的通知,您需要将一些 javascript 注入视图中,并与其交互。这可能比其价值更多的努力。

What I want to achieve is that when the browser finishes rendering the page I want it to emit the signal

RenderProcessTerminated doesn't mean "finished rendering the page". It means that the operating system's process that was used for rendering has terminated abnormally. It happens e.g. when the renderer crashes. Qt documentation clearly states:

This signal is emitted when the render process is terminated with a non-zero exit status. terminationStatus is the termination status of the process and exitCode is the status code with which the process terminated.

In English, the verb you'd be looking for is finished instead of terminated. The former implies the latter: when a process is finished, it has terminated. But the reverse is not necessary: a process may well terminate before it's finished with its task, e.g. if it crashes, or is terminated when the parent process exits, etc. But also: the RenderProcess doesn't mean "a task of rendering something". It literally means "the operating system process that performs the rendering". That process normally must stay alive for as long as you have any web views active.

The only signal I can see that approximates what you want is QWebEngineView::loadFinished(bool ok). Try it out.

Ohterwise, for finer notifications, you'll need to inject some javascript into the view, and interact with it. It may be more effort than it's worth.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文