Skip to content

Instantly share code, notes, and snippets.

@poptosic
Last active March 3, 2017 11:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save poptosic/8af03a4c736c57658c3b66a082834035 to your computer and use it in GitHub Desktop.
Save poptosic/8af03a4c736c57658c3b66a082834035 to your computer and use it in GitHub Desktop.
Demonstrates a possible regression in PyQt5.8 where calling QJSValue.toVariant() on a javascript object passed from QML which contains null as a value of one of its attributes, leads to this error: TypeError: unable to convert a C++ 'QVariantMap' instance to a Python object.
import sys
from PyQt5.QtCore import QObject, pyqtSlot
from PyQt5.QtCore import QVariant
from PyQt5.QtQml import QQmlApplicationEngine
from PyQt5.QtWidgets import QApplication
class Context(QObject):
@pyqtSlot(QVariant)
def test(self, data):
print(data.toVariant())
application = QApplication(sys.argv)
context = Context()
engine = QQmlApplicationEngine()
engine.rootContext().setContextProperty('context', context)
engine.load('test.qml')
sys.exit(application.exec_())
import QtQuick 2.0
import QtQuick.Window 2.0
Window {
visible: true
Component.onCompleted: context.test({'test': null})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment