Advertisement
Guest User

Untitled

a guest
Feb 7th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. // main.py
  2. from PyQt5.QtCore import pyqtSlot, QObject
  3. from PyQt5.QtGui import QGuiApplication
  4. from PyQt5.QtQml import QQmlApplicationEngine
  5. import sys
  6.  
  7.  
  8. class Bot(QObject):
  9. def __init__(self):
  10. super(Bot, self).__init__()
  11.  
  12. @pyqtSlot(str)
  13. def say(self, what):
  14. print("Bot say: {}".format(what))
  15.  
  16.  
  17. def main():
  18. """
  19. #include <QGuiApplication>
  20. #include <QQmlApplicationEngine>
  21.  
  22. int main(int argc, char *argv[])
  23. {
  24. QGuiApplication app(argc, argv);
  25.  
  26. QQmlApplicationEngine engine;
  27. engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
  28.  
  29. return app.exec();
  30. }
  31. """
  32. app = QGuiApplication(sys.argv)
  33. engine = QQmlApplicationEngine()
  34. context = engine.rootContext()
  35. bot = Bot()
  36. context.setContextProperty('Bot', bot)
  37. engine.load("Bot.qml")
  38. return app.exec_()
  39.  
  40.  
  41. if __name__ == '__main__':
  42. sys.exit(main())
  43.  
  44. // Bot.qml
  45. import QtQuick 2.5
  46. import QtQuick.Controls 1.4
  47.  
  48.  
  49. ApplicationWindow {
  50. id: appWindow
  51.  
  52. Text {
  53. text: "Hello world"
  54. }
  55.  
  56. Component.onCompleted: {
  57. visible = true
  58. Bot.say('Hi')
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement