在 Qt (C++) 中重新实现 shouldInterruptJavaScript() [英] reimplement the shouldInterruptJavaScript() in Qt (C++)
问题描述
根据 Qt for QWebPage [Slot ShhoudInteruptJavaScript] 的帮助,位于 此处:
<块引用>当 JavaScript 程序长时间运行时会调用此函数.
如果用户想要停止 JavaScript,实现应该返回 true;否则为假.
默认实现使用 QMessageBox::information 和 QMessageBox::Yes 和 QMessageBox::No 按钮执行查询.
<乙>警告:由于二进制兼容性限制,此函数不是虚拟的.如果您想在 QWebPage 子类中提供您自己的实现,请在您的子类中重新实现 shouldInterruptJavaScript() 插槽.QtWebKit 会动态检测插槽并调用它.
我不希望 javascript 长时间运行时 qt 显示消息.
那么,我该如何重新实现 ShoudInteruptJavaScript?
我应该在哪里创建它?
请给我看样品谢谢
您需要的所有信息都在文档中.
创建一个继承自 QWebPage 的新自定义类,确保它是一个 Q_OBJECT 来接收信号.
<前>类 MyFunkyPage :公共 QWebPage {Q_OBJECT公共插槽:bool shouldInterruptJavaScript() {QApplication::processEvents(QEventLoop::AllEvents, 42);//忽略错误返回假;}};将 QWebView 的页面设置为 QWebPage 的自定义子类.
<前>setPage(new MyFunkyPage());然后,当您的页面收到此信号时,它不会停止脚本的执行,也不会显示对话框.
According to the help of Qt for QWebPage [Slot ShoudInteruptJavaScript], located here:
This function is called when a JavaScript program is running for a long period of time.
If the user wanted to stop the JavaScript the implementation should return true; otherwise false.
The default implementation executes the query using QMessageBox::information with QMessageBox::Yes and QMessageBox::No buttons.
Warning: Because of binary compatibility constraints, this function is not virtual. If you want to provide your own implementation in a QWebPage subclass, reimplement the shouldInterruptJavaScript() slot in your subclass instead. QtWebKit will dynamically detect the slot and call it.
I don't want qt show a message when javascript runnig for long period of time.
So, how can i reimplement ShoudInteruptJavaScript?
and where should i create it?
Please show me a sample
Thanks
All the info you need is in the documentation.
Create a new custom class that inherits from QWebPage, make sure it's a Q_OBJECT to receive signals.
class MyFunkyPage : public QWebPage { Q_OBJECT public slots: bool shouldInterruptJavaScript() { QApplication::processEvents(QEventLoop::AllEvents, 42); // Ignore the error return false; } };
Set the page of your QWebView to a custom subclass of QWebPage.
setPage(new MyFunkyPage());
Then when your page gets this signal it won't stop the script from executing, and it won't show a dialog.
这篇关于在 Qt (C++) 中重新实现 shouldInterruptJavaScript()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!