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

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 12 Apr 2024, 18:33 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

    A G 2 Replies Last reply 12 Apr 2024, 20:20
    0
    • T Tobias83
      12 Apr 2024, 18:33

      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

      A Offline
      A Offline
      Axel Spoerl
      Moderators
      wrote on 12 Apr 2024, 20:20 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
        12 Apr 2024, 18:33

        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

        G Offline
        G Offline
        GrecKo
        Qt Champions 2018
        wrote on 13 Apr 2024, 10:26 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 14 Apr 2024, 08:45
        2
        • G GrecKo
          13 Apr 2024, 10:26

          @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 14 Apr 2024, 08:45 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
          • G GrecKo
            13 Apr 2024, 10:26

            @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 14 Apr 2024, 12:20 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
            • G GrecKo
              13 Apr 2024, 10:26

              @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 18 Apr 2024, 17:24 last edited by
              #6

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

              J A 2 Replies Last reply 19 Apr 2024, 07:08
              0
              • T Tobias83
                18 Apr 2024, 17:24

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

                J Offline
                J Offline
                jsulm
                Lifetime Qt Champion
                wrote on 19 Apr 2024, 07:08 last edited by
                #7
                This post is deleted!
                G 1 Reply Last reply 19 Apr 2024, 08:31
                0
                • T Tobias83
                  18 Apr 2024, 17:24

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

                  A Offline
                  A Offline
                  Axel Spoerl
                  Moderators
                  wrote on 19 Apr 2024, 08:28 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
                  • J jsulm
                    19 Apr 2024, 07:08

                    This post is deleted!

                    G Offline
                    G Offline
                    GrecKo
                    Qt Champions 2018
                    wrote on 19 Apr 2024, 08:31 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 22 Apr 2024, 17:00
                    1
                    • G GrecKo
                      19 Apr 2024, 08:31

                      @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 22 Apr 2024, 17:00 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 9 Jul 2024, 19:14

                      10/10

                      22 Apr 2024, 17:00

                      • Login

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