main.py 632 B

1234567891011121314151617181920212223242526
  1. import os
  2. import sys
  3. import time
  4. import threading
  5. from PyQt5 import QtCore, QtGui, QtQml
  6. THIS_DIR = os.path.dirname(os.path.abspath(__file__))
  7. class JSManager(QtCore.QObject):
  8. text = QtCore.pyqtSignal(QtCore.QVariant)
  9. @QtCore.pyqtSlot()
  10. def get_text(self):
  11. def go():
  12. _text = "Hello from JavaScript"
  13. self.text.emit(_text)
  14. threading.Thread(target=go).start()
  15. def main():
  16. app = QtGui.QGuiApplication(sys.argv)
  17. QtQml.qmlRegisterType(JSManager, 'JSManager', 1, 0, 'JSManager')
  18. engine = QtQml.QQmlApplicationEngine(os.path.join(THIS_DIR, "main.qml"))
  19. app.exec_()