[PyQt] Need help with PyQt and QWebChannel
Detlev Offenbach
detlev at die-offenbachs.de
Tue Mar 15 20:14:42 GMT 2016
Hi,
I am in the process of porting the eric web browser from QtWebKit to QtWebEngine. In
this process I am facing an issue I would need some help to resolve it.
I have a web page that contains a JavaScript part like:
<script type="text/javascript">
function update()
{
alert(window.external.searchUrl());
document.getElementById('footer').innerHTML = window.external.providerString()
+ ' | <a href="http://eric-ide.python-projects.org/">'
+ '@ERIC_LINK@</a>';
document.getElementById('lineEdit').placeholder =
window.external.providerString();
// Try to change the direction of the page:
var newDir = '@QT_LAYOUT_DIRECTION@';
newDir = newDir.toLowerCase();
if ((newDir != 'ltr') && (newDir != 'rtl'))
newDir = 'ltr';
document.getElementsByTagName('body')[0].setAttribute('dir', newDir);
}
function formSubmitted()
{
var string = lineEdit.value;
if (string.length == 0)
return;
var url = window.external.searchUrl(string);
window.location.href = url;
}
// Initialize
if (window.external) {
update();
} else {
document.addEventListener('_eric_external_created', update);
}
</script>
The "window.external.searchUrl" method is implemented in an object registered with a
QWebChannel like
@pyqtSlot(str, result=str)
def searchUrl(self, searchStr):
However, the alert() call in the above script always returns 'undefined', that is the function
'searchUrl' is not registered with it.
What am I doing wrong?
Detlev
PS: Full code can be retrieved from the eric repository at http://die-offenbachs.homelinux.org:48888/hg/eric/--
*Detlev Offenbach*
detlev at die-offenbachs.de
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20160315/5a9b5e19/attachment.html>
More information about the PyQt
mailing list