[PyQt] Values returned to python from QML function

michael h michaelkenth at gmail.com
Tue Feb 18 01:56:27 GMT 2014


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_())
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20140217/6fdfaeb9/attachment.html>


More information about the PyQt mailing list