Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. qmlRegisterTypeSingleton with contextData error while using PySide6
Forum Updated to NodeBB v4.3 + New Features

qmlRegisterTypeSingleton with contextData error while using PySide6

Scheduled Pinned Locked Moved Solved QML and Qt Quick
9 Posts 2 Posters 613 Views 1 Watching
  • 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.
  • R Offline
    R Offline
    RLayman
    wrote on last edited by
    #1

    I've been having this issue for a long time now. The existing code worked fine for years and didn't start failing until after a QT update over six months ago. If you register a singleton using PySide6, you will get a 'Cannot assign object to list property "contextData"' error message when the QML code has a ListModel. This happens even if the singleton is not being used by the QML code. If you remove qmlRegisterSingletonType, the error goes away. I've searched the internet and have not seen this error happening due to adding a singleton, so I'm not sure what's going on.

    # singleton.py
    
    from PySide6.QtCore import Qt
    from PySide6.QtCore import QObject
    
    class Singleton(QObject):
    
        def __init__(self):
            super().__init__()
    
    # app
    
    import sys
    from PySide6.QtCore import Qt, QObject, QAbstractListModel, QUrl, QByteArray, Signal, Slot, Property
    from PySide6.QtGui import QGuiApplication
    from PySide6.QtQml import QQmlApplicationEngine
    from PySide6 import QtQml
    from singleton import Singleton 
    
    _singleton = Singleton()
    
    def singleton_callback(self):
        return _singleton
    
    if __name__ == "__main__":
        app = QGuiApplication(sys.argv)
        engine = QQmlApplicationEngine()
    
        # This Fails 
        QtQml.qmlRegisterSingletonType(Singleton, 'Test', 1, 0, 'Singleton',singleton_callback)
    
        # This Works
        #QtQml.qmlRegisterType(Singleton, 'Test', 1, 0, 'Singleton')
    
        engine.quit.connect(app.quit)
        engine.load('main.qml')
        sys.exit(app.exec())
    
    // main.qml
    import QtQuick
    import QtQuick.Controls
    import Test 1.0
    
    ApplicationWindow {
        id: main
    
        width: 450 
        height: 450 
        title: "Singleton Test" 
        visible: true
    
        ListModel { id: myModel }
    
        Component.onCompleted: {}
    }
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #7

      You are doing things out of order.

      You need to register the Singleton before creating the engine.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #2

        Hi,

        Do you have the same issue with PySide6 ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • R Offline
          R Offline
          RLayman
          wrote on last edited by
          #3

          I'm assuming this is an issue between PySide6 and Qt, but I'm not aware of who is to blame.

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #4

            Sorry, I misread something and thought you were using PyQt6...

            Which version of PySide6 are you using ?
            How did you install it ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • R Offline
              R Offline
              RLayman
              wrote on last edited by
              #5
              This post is deleted!
              1 Reply Last reply
              0
              • R Offline
                R Offline
                RLayman
                wrote on last edited by
                #6

                I am using Pyside 6.8.1.1-2 with Qt 6.8.1-1 on an ArchLinux system. This issue has been going on for over six months, and it's been updated several times since then, so it's not a recent issue. I've also wiped the whole system and done a clean install, but I still have the same issue.

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #7

                  You are doing things out of order.

                  You need to register the Singleton before creating the engine.

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • R Offline
                    R Offline
                    RLayman
                    wrote on last edited by
                    #8

                    Sorry about the late reply; I got busy with work. That fixed it! It's kind of odd since it always worked fine up until a few months ago. I'll have to look in the repo to see if something was changed that I forgot about, but I don't remember changing anything in the source at that time. Anyway, thank you for the help!

                    1 Reply Last reply
                    0
                    • SGaistS SGaist has marked this topic as solved on
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #9

                      You're welcome !

                      You know, inverting lines can happen quickly and innocuously :-)
                      Anyway, now you're back on track.

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      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