Last active
March 3, 2017 11:02
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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