pyqt-webkit与javascript交互的问题

来源:互联网 发布:求购0信誉淘宝店铺 编辑:程序博客网 时间:2024/04/26 12:17

Qtwebkit中关于void QWebFrame::addToJavaScriptWindowObject的描述如下:

 

 

void QWebFrame::addToJavaScriptWindowObject ( const QString & name, QObject * object )

 

Make object available under name from within the frame's JavaScript context. The object will be inserted as a child of the frame's window object.

Qt properties will be exposed as JavaScript properties and slots as JavaScript methods.


If you want to ensure that your QObjects remain accessible after loading a new URL, you should add them in a slot connected to the javaScriptWindowObjectCleared() signal.

If Javascript is not enabled for this page, then this method does nothing.

The object will never be explicitly deleted by QtWebKit.

注意彩色文字部分,javascript调用的QObject的方法必须是槽才可以,而我用的pyqt,其中定义槽函数是有很多种方法,有什么旧的方法新的方法,我采用的是使用  @pyqtSlot()

当槽有参数时必须在@pyqtSlot(str)添加参数,同样当槽函数有返回值是也必须添加@pyqtSlot(result=int),否则在javascript代码中调用时都回失败

 

 

 

 

原创粉丝点击