[PyQt] Values returned to python from QML function

Phil Thompson phil at riverbankcomputing.com
Fri Feb 21 15:22:14 GMT 2014


On 18-02-2014 1:56 am, michael h wrote:
> Ran across some unexpected behavior while fiddling with QML.. See
> comments in python source below.
>
> Windows 7, Python 3.3.2 x86
> PYQT_VERSION_STR = 5.2.1-snapshot-c8f5b569c377
>
> SIP_VERSION_STR = 4.15.5-snapshot-d45411f2a001
>
> Thanks,
> Michael
>
> // ---- return.qml ----
>
> import QtQuick 2.0
> import QtQuick.Controls 1.1
>
> ApplicationWindow {
>     id: main; visible: true;
>     function logThing(thing) { console.log(JSON.stringify(thing)); }
>
>     function getThing(a) { return a; }
> }
>
> # ---- return.py ----
>
> import sys
> from PyQt5.QtWidgets import QApplication
> from PyQt5.QtQml import QQmlApplicationEngine
>
> if __name__ == __main__:
>     app = QApplication(sys.argv)
>     eng = QQmlApplicationEngine(return.qml)
>     root = eng.rootObjects()[0]
>     root.logThing({a: 42}) # works
>     print (root.getThing(simple)) # works
>     print (root.getThing({b: 41})) # Crash or sometimes an error: 
>         # "Trying to construct an instance of an invalid type,
> type id: <#>"
>         # and None is printed
>     sys.exit(app.exec_())

Should be fixed in tonight's snapshot.

Thanks,
Phil


More information about the PyQt mailing list