Skip to content

Instantly share code, notes, and snippets.

@Siecje
Last active February 15, 2017 21:43
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 Siecje/c93f4faf15baa89d4fd0c9ff86d22a6a to your computer and use it in GitHub Desktop.
Save Siecje/c93f4faf15baa89d4fd0c9ff86d22a6a to your computer and use it in GitHub Desktop.
Trying to test a QML type registered fro Python
(venv) ~ $ python test_qml.py
QQmlApplicationEngine failed to load component
:27 Type TestCase unavailable
file:///home/siecje/venv/lib/python3.5/site-packages/PyQt5/Qt/qml/QtTest/TestCase.qml:43 module "Qt.test.qtestroot" is not installed
#!/usr/bin/env python
import sys
from PyQt5 import Qt, QtCore, QtGui, QtQml, QtWidgets
class OutputType(QtCore.QObject):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.output = ""
@QtCore.pyqtSlot()
def ChangeOutput(self):
self.output = "Hello"
QML = b"""
import QtQuick 2.0
import QtQuick.Controls 1.4
import QtTest 1.1
import OutputType 1.0
Item {
width: 800
height: 600
visible: true
OutputType {
id: outputType
}
Text {
id: txt
text: outputType.output
}
Button {
id: btn
onClicked: {
outputType.ChangeOutput()
}
}
TestCase {
name: "MouseTests"
function test_clicked(){
compare(txt.text, "")
btn.clicked()
compare(txt.text, "Hello")
}
}
}
"""
app = QtWidgets.QApplication(sys.argv + ["-nograb"])
QtQml.qmlRegisterType(OutputType, 'OutputType', 1, 0, 'OutputType')
engine = QtQml.QQmlApplicationEngine()
engine.loadData(QML)
sys.exit(app.exec_())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment