loginoleg
loginoleg

Reputation: 27

Send msg betwen js and python in QtWebKit

I found this topic in wiki: https://wiki.qt.io/Using-QtWebKit-and-QML-with-PySide. But I cannot run the sample program from it. I use pyqt4 and get the following error

$ ./main1.py 
Traceback (most recent call last): File “./main1.py”, line 35, in <module> view.setSource(file.replace(’.py’, ‘.qml’))
TypeError: QDeclarativeView.setSource(QUrl): argument 1 has unexpected type ‘str’

Anybody have souces code from this toturial? Maybe my problem is that I use pyqt4 instead of pyside?

Upvotes: 0

Views: 278

Answers (1)

Avaris
Avaris

Reputation: 36715

You actually have enough information in the exception.

TypeError: QDeclarativeView.setSource(QUrl): argument 1 has unexpected type ‘str’

Here, QDeclarativeView.setSource(QUrl) says setSource method for QDeclarativeView expects a QUrl argument and instead you given a plain string.

Try this:

view.setSource(QtCore.QUrl(file.replace(’.py’, ‘.qml’)))

Of course, you also need to import QtCore.

Regarding whether this is different in PyQt4 vs PySide: I doubt that. PySide documentation for QDeclarativeView.setSource also states a QUrl argument. But PySide may change strings to QUrl under the hood. That I am not sure.

Upvotes: 1

Related Questions