Passer d'une page QML à une autre depuis Python
bonjour
en faite je suis débutant en QML et PyQt, j'ai trouvé un souci de passé d'une page QML a une autre puis on utilisent QObject (property et setproperty).
donc moi j'ai reussit a afficher la 2eme page QML puis quand j'utilise le setproperty j'aurai cette erreur: AttributError: 'NoneType' object has no attribute 'setProperty'.
et voici mon code :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| #!/usr/bin/env python
# -*- coding: utf-8 -*-
import Classe
import sys
from PyQt5.QtWidgets import QApplication
from PyQt5.QtQml import QQmlApplicationEngine
from PyQt5.QtCore import QObject, pyqtSlot, QVariant
# Classe servant dans l'interaction.
class MainApp(QObject):
def __init__(self, context, parent=None):
super(MainApp, self).__init__()
# Recherche d'un enfant appelé myButton dont le signal clicked sera connecté à la fonction test3
self.win = parent
self.win.findChild(QObject, "ObjClasse").clicked.connect(self.test3)
self.ctx = context
def test3(self):
engine.load('Classe.qml')
self.win.findChild(QObject, "labelCo").setProperty("text", "hello world") ##l'erreur est ici
if __name__ == "__main__":
app = QApplication(sys.argv)
engine = QQmlApplicationEngine()
ctx = engine.rootContext()
engine.load('main.qml')
win = engine.rootObjects()[0]
py_mainapp = MainApp(ctx,win)
ctx.setContextProperty("py_MainApp", py_mainapp)
win.show()
sys.exit(app.exec()) |
si vous avez un petit exemple qui peux m'aidez merci de me le transférez