Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. QQMLApplicationEngine failed to load component; Number generator is not a type
QtWS25 Last Chance

QQMLApplicationEngine failed to load component; Number generator is not a type

Scheduled Pinned Locked Moved Unsolved Qt for Python
pythonqt for pythonpyside
2 Posts 2 Posters 1.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    SCP173
    wrote on last edited by SCP173
    #1

    I am trying to run an example from QT5 Cadaques book - the full official source code can be found from this link here in this directory: ch20-python-assets\ch20-python\src\class

    I get a QQMLApplicationEngine failed to load component; Number generator is not a type error
    when running the class.py file. I am using Python 3.8.9 and PySide6 on Windows 10 Pro. Am I missing something obvious?

    eyllanescE 1 Reply Last reply
    0
    • S SCP173

      I am trying to run an example from QT5 Cadaques book - the full official source code can be found from this link here in this directory: ch20-python-assets\ch20-python\src\class

      I get a QQMLApplicationEngine failed to load component; Number generator is not a type error
      when running the class.py file. I am using Python 3.8.9 and PySide6 on Windows 10 Pro. Am I missing something obvious?

      eyllanescE Offline
      eyllanescE Offline
      eyllanesc
      wrote on last edited by
      #2

      @SCP173

      Try with:

      import sys
      import random
      
      from PySide6.QtGui import QGuiApplication
      from PySide6.QtQml import QQmlApplicationEngine, qmlRegisterType
      from PySide6.QtCore import QUrl
      
      from PySide6.QtCore import QObject, Signal, Slot
      
      class NumberGenerator(QObject):
          def __init__(self):
              QObject.__init__(self)
          
          nextNumber = Signal(int)
      
          @Slot()
          def giveNumber(self):
              self.nextNumber.emit(random.randint(0, 99))
      
      
      if __name__ == '__main__':
          app = QGuiApplication(sys.argv)
          engine = QQmlApplicationEngine()
          
          qmlRegisterType(NumberGenerator, 'Generators', 1, 0, 'NumberGenerator')
          
          engine.load(QUrl("main.qml"))
          
          if not engine.rootObjects():
              sys.exit(-1)    
          
          sys.exit(app.exec())
      
      import QtQuick 2.0
      import QtQuick.Window 2.0
      import QtQuick.Controls 2.0
      
      import Generators 1.0
      
      Window {
          id: root
          
          width: 640
          height: 480
          visible: true
          title: "Hello Python World!"
          
          Flow {
              Button {
                  text: "Give me a number!"
                  onClicked: numberGenerator.giveNumber();
              }
              Label {
                  id: numberLabel
                  text: "no number"
              }
          }
          
          NumberGenerator {
              id: numberGenerator
              
              // Signal argument names are not propagated from Python to QML, so we need to re-emit the signal
              signal reNextNumber(int number)
              Component.onCompleted: numberGenerator.nextNumber.connect(reNextNumber)
          }
          
          Connections {
              target: numberGenerator
              function onReNextNumber(number){
                  numberLabel.text = number
              }
          }
      }
      

      If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved