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. Qt6 QAbstractListModel - constructor with two arguments - qml Element is not creatable
QtWS25 Last Chance

Qt6 QAbstractListModel - constructor with two arguments - qml Element is not creatable

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
modelviewconstructorentrymodelqml
10 Posts 4 Posters 1.1k 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.
  • T Offline
    T Offline
    Tobias83
    wrote on last edited by
    #1

    Hey dear Qt forum,

    I already made a post in stackoverflow, but I need some special Qt advise, I think:
    stackoverflow: construcor with two elements

    I want to create a graphical output with QML for a cpp particle system. Therefor I found out a construction, which worked for Qt5, but now errors with "qml object is not creatable": I use a QAbstractListModel Entrymodel class as wrapper for my System* class. So I made constructor for my Entrymodel, that has two arguments: QObject and System*. The argument System* pointer is thereby copied to System* pointer wrapped by the Entrymodel class. Otherwise the particle simulation would freeze at its starting configuration. But, with the two argument constructor, the resent state of the particle simulation is every times transferred to the next construction of the Entrymodel. There are parts of my code in the stackoverflow post.

    However this worked pretty good with Qt5, but with Qt6 it errors. How can I make that work again?

    Kind regards,
    Tobias

    Axel SpoerlA GrecKoG 2 Replies Last reply
    0
    • T Tobias83

      Hey dear Qt forum,

      I already made a post in stackoverflow, but I need some special Qt advise, I think:
      stackoverflow: construcor with two elements

      I want to create a graphical output with QML for a cpp particle system. Therefor I found out a construction, which worked for Qt5, but now errors with "qml object is not creatable": I use a QAbstractListModel Entrymodel class as wrapper for my System* class. So I made constructor for my Entrymodel, that has two arguments: QObject and System*. The argument System* pointer is thereby copied to System* pointer wrapped by the Entrymodel class. Otherwise the particle simulation would freeze at its starting configuration. But, with the two argument constructor, the resent state of the particle simulation is every times transferred to the next construction of the Entrymodel. There are parts of my code in the stackoverflow post.

      However this worked pretty good with Qt5, but with Qt6 it errors. How can I make that work again?

      Kind regards,
      Tobias

      Axel SpoerlA Offline
      Axel SpoerlA Offline
      Axel Spoerl
      Moderators
      wrote on last edited by
      #2

      @Tobias83
      The class has to be default-constructable, so the QML engine can create meta objects. Maybe you can solve that with a default argument.

      Software Engineer
      The Qt Company, Oslo

      1 Reply Last reply
      0
      • T Tobias83

        Hey dear Qt forum,

        I already made a post in stackoverflow, but I need some special Qt advise, I think:
        stackoverflow: construcor with two elements

        I want to create a graphical output with QML for a cpp particle system. Therefor I found out a construction, which worked for Qt5, but now errors with "qml object is not creatable": I use a QAbstractListModel Entrymodel class as wrapper for my System* class. So I made constructor for my Entrymodel, that has two arguments: QObject and System*. The argument System* pointer is thereby copied to System* pointer wrapped by the Entrymodel class. Otherwise the particle simulation would freeze at its starting configuration. But, with the two argument constructor, the resent state of the particle simulation is every times transferred to the next construction of the Entrymodel. There are parts of my code in the stackoverflow post.

        However this worked pretty good with Qt5, but with Qt6 it errors. How can I make that work again?

        Kind regards,
        Tobias

        GrecKoG Offline
        GrecKoG Offline
        GrecKo
        Qt Champions 2018
        wrote on last edited by
        #3

        @Tobias83 this model seems to have its place in your business layer. Do you want to instantiate multiple of them? With varying properties?

        If not I would advise you to expose it to QML as a singleton.

        T 3 Replies Last reply
        2
        • GrecKoG GrecKo

          @Tobias83 this model seems to have its place in your business layer. Do you want to instantiate multiple of them? With varying properties?

          If not I would advise you to expose it to QML as a singleton.

          T Offline
          T Offline
          Tobias83
          wrote on last edited by Tobias83
          #4

          @GrecKo In the main function, I create an System object with argc, argv arguments and write this particle system to a parameters file. The constructor System() reads this parameters file by default when it is called by Qt. As I understood Qt right, there is a never ending loop between initiating a QObject with the QObject before. When I initiate the System every times new, it will always have its starting configuration. Therefor there is a continuous communication between the entrymodel and the qml object. But when I transfer it from one to the next QObject as pointer, I can make a continuous simulation. Or, what do you mean with multiple? And how does "singleton" work - I already read about that, but didn't understood it well.

          1 Reply Last reply
          0
          • GrecKoG GrecKo

            @Tobias83 this model seems to have its place in your business layer. Do you want to instantiate multiple of them? With varying properties?

            If not I would advise you to expose it to QML as a singleton.

            T Offline
            T Offline
            Tobias83
            wrote on last edited by
            #5

            @GrecKo There was some mistake in the previous answer ...
            In the main function, I create an System object with argc, argv arguments and write this particle system to a parameters file. The constructor System() reads this parameters file by default when it is called by Qt. As I understood Qt right, there is a never ending loop between initiating a QObject with the QObject before. When I initiate the System every times new, it will always have its starting configuration. But when I transfer it from one to the next QObject as pointer, I can make a continuous simulation. Therefor there is a continuous communication between the entrymodel and the qml object. Or, what do you mean with multiple? And how does "singleton" work - I already read about that, but didn't understood it well.

            1 Reply Last reply
            0
            • GrecKoG GrecKo

              @Tobias83 this model seems to have its place in your business layer. Do you want to instantiate multiple of them? With varying properties?

              If not I would advise you to expose it to QML as a singleton.

              T Offline
              T Offline
              Tobias83
              wrote on last edited by
              #6

              @GrecKo Is there a good howto for singletons? I didn't found one ...

              jsulmJ Axel SpoerlA 2 Replies Last reply
              0
              • T Tobias83

                @GrecKo Is there a good howto for singletons? I didn't found one ...

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #7
                This post is deleted!
                GrecKoG 1 Reply Last reply
                0
                • T Tobias83

                  @GrecKo Is there a good howto for singletons? I didn't found one ...

                  Axel SpoerlA Offline
                  Axel SpoerlA Offline
                  Axel Spoerl
                  Moderators
                  wrote on last edited by
                  #8

                  @Tobias83
                  https://doc.qt.io/QtForMCUs-2.5/qtul-qml-singleton.html

                  Software Engineer
                  The Qt Company, Oslo

                  1 Reply Last reply
                  0
                  • jsulmJ jsulm

                    This post is deleted!

                    GrecKoG Offline
                    GrecKoG Offline
                    GrecKo
                    Qt Champions 2018
                    wrote on last edited by GrecKo
                    #9

                    @Axel-Spoerl said in Qt6 QAbstractListModel - constructor with two arguments - qml Element is not creatable:

                    @Tobias83
                    https://doc.qt.io/QtForMCUs-2.5/qtul-qml-singleton.html

                    Not relevant to the needs of Tobias83. We are not talking about an object defined in QML.

                    @Tobias83 said in Qt6 QAbstractListModel - constructor with two arguments - qml Element is not creatable:

                    @GrecKo Is there a good howto for singletons? I didn't found one ...

                    The official ones are not that practical I'm afraid: https://doc.qt.io/qt-6/qqmlengine.html#QML_SINGLETON
                    To expose a business class I would recommend the last example.

                    To reduce the boiler plate I've wrote some macros wrapping the above and Ekke a blog post explaining the context and how they can be used: https://ekkesapps.wordpress.com/qt-6-in-action/qmake-cmake/qml_singleton/

                    T 1 Reply Last reply
                    1
                    • GrecKoG GrecKo

                      @Axel-Spoerl said in Qt6 QAbstractListModel - constructor with two arguments - qml Element is not creatable:

                      @Tobias83
                      https://doc.qt.io/QtForMCUs-2.5/qtul-qml-singleton.html

                      Not relevant to the needs of Tobias83. We are not talking about an object defined in QML.

                      @Tobias83 said in Qt6 QAbstractListModel - constructor with two arguments - qml Element is not creatable:

                      @GrecKo Is there a good howto for singletons? I didn't found one ...

                      The official ones are not that practical I'm afraid: https://doc.qt.io/qt-6/qqmlengine.html#QML_SINGLETON
                      To expose a business class I would recommend the last example.

                      To reduce the boiler plate I've wrote some macros wrapping the above and Ekke a blog post explaining the context and how they can be used: https://ekkesapps.wordpress.com/qt-6-in-action/qmake-cmake/qml_singleton/

                      T Offline
                      T Offline
                      Tobias83
                      wrote on last edited by
                      #10

                      @GrecKo Dear GrecKo,
                      in the qml_singleton.h should I change the word "Type" to "System", because my Particlesystem is called like that?
                      Where have I to introduce my Hardcore_Entrymodel - is it the UnsafeArea or is it the ApplicationUI class?
                      I tend to UnsafeArea=Hardcore_Entrymodel and to leave the names "ApplicationUI" and "Type##QmlSingleton", but I'm not sure ...

                      1 Reply Last reply
                      0
                      • T Tobias83 referenced this topic on

                      • Login

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