Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // main.py
- from PyQt5.QtCore import pyqtSlot, QObject
- from PyQt5.QtGui import QGuiApplication
- from PyQt5.QtQml import QQmlApplicationEngine
- import sys
- class Bot(QObject):
- def __init__(self):
- super(Bot, self).__init__()
- @pyqtSlot(str)
- def say(self, what):
- print("Bot say: {}".format(what))
- def main():
- """
- #include <QGuiApplication>
- #include <QQmlApplicationEngine>
- int main(int argc, char *argv[])
- {
- QGuiApplication app(argc, argv);
- QQmlApplicationEngine engine;
- engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
- return app.exec();
- }
- """
- app = QGuiApplication(sys.argv)
- engine = QQmlApplicationEngine()
- context = engine.rootContext()
- bot = Bot()
- context.setContextProperty('Bot', bot)
- engine.load("Bot.qml")
- return app.exec_()
- if __name__ == '__main__':
- sys.exit(main())
- // Bot.qml
- import QtQuick 2.5
- import QtQuick.Controls 1.4
- ApplicationWindow {
- id: appWindow
- Text {
- text: "Hello world"
- }
- Component.onCompleted: {
- visible = true
- Bot.say('Hi')
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement