Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. Singleton vs uncreatableType
Forum Updated to NodeBB v4.3 + New Features

Singleton vs uncreatableType

Scheduled Pinned Locked Moved Unsolved C++ Gurus
7 Posts 3 Posters 1.1k 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.
  • D Offline
    D Offline
    damianatorrpm
    wrote on last edited by
    #1

    Happy New Year!

    I wonder which one is (in theory) supposed to be the better solution.
    I have a QAbstractListModel that should be re-used in multiple QML Components.
    The model will always be the same.

    Currently I have it registered as a Singleton and use it like this.

    ...
    model: MyModelSingleton
    ...
    

    Would it make a difference in using instead of a Singleton a qmlRegisterUncreatableType?
    IIRC the singleton would be able to only be instantiated once in QML (though in the above case is it even instantiated as there is no MyModelSingleton { }? ) ?

    1 Reply Last reply
    0
    • fcarneyF Offline
      fcarneyF Offline
      fcarney
      wrote on last edited by
      #2

      Could you please provide an example of what you are talking about? (QML and C++)
      At this point I cannot quite make out what you are referring to and if it is in QML or C++.

      C++ is a perfectly valid school of magic.

      1 Reply Last reply
      0
      • D Offline
        D Offline
        damianatorrpm
        wrote on last edited by
        #3

        C++ Classes are registered in QML using various functions:

        1. qmlRegisterType
        2. qmlRegisterUncreatableType
        3. qmlRegisterSingleton

        2 and 3 are basically the same but 3) can be instantiated once in QML 2) is forbidden to be instantiated.
        I want to know a) what is the preferred way b) in the example 3) should also have been instantiated 0 times, right?

        J.HilkJ 1 Reply Last reply
        0
        • D damianatorrpm

          C++ Classes are registered in QML using various functions:

          1. qmlRegisterType
          2. qmlRegisterUncreatableType
          3. qmlRegisterSingleton

          2 and 3 are basically the same but 3) can be instantiated once in QML 2) is forbidden to be instantiated.
          I want to know a) what is the preferred way b) in the example 3) should also have been instantiated 0 times, right?

          J.HilkJ Offline
          J.HilkJ Offline
          J.Hilk
          Moderators
          wrote on last edited by
          #4

          @damianatorrpm said in Singleton vs uncreatableType:

          2 and 3 are basically the same but 3) can be instantiated once in QML 2) is forbidden to be instantiated.

          where did you get that information from ?

          qmlRegisterUncreatableType is used to register c++ types that you want to know of in qml, for example the class contained enums and you want to use them in QML.

          Has 0 to do with singletons


          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          D 1 Reply Last reply
          1
          • J.HilkJ J.Hilk

            @damianatorrpm said in Singleton vs uncreatableType:

            2 and 3 are basically the same but 3) can be instantiated once in QML 2) is forbidden to be instantiated.

            where did you get that information from ?

            qmlRegisterUncreatableType is used to register c++ types that you want to know of in qml, for example the class contained enums and you want to use them in QML.

            Has 0 to do with singletons

            D Offline
            D Offline
            damianatorrpm
            wrote on last edited by
            #5

            @J-Hilk That's basically what I said.
            What is the difference between a Singleton that you do not instantiate and an uncreatable type?
            AFAIK The Instantiation happens when you do Object {}
            which the following does not:

            ...
            model: MyModelSingleton //an QAbstractListModel
            ...
            

            So should you use for above rather and uncreatable type or a singleton?

            J.HilkJ 1 Reply Last reply
            0
            • D damianatorrpm

              @J-Hilk That's basically what I said.
              What is the difference between a Singleton that you do not instantiate and an uncreatable type?
              AFAIK The Instantiation happens when you do Object {}
              which the following does not:

              ...
              model: MyModelSingleton //an QAbstractListModel
              ...
              

              So should you use for above rather and uncreatable type or a singleton?

              J.HilkJ Offline
              J.HilkJ Offline
              J.Hilk
              Moderators
              wrote on last edited by
              #6

              @damianatorrpm
              maybe this chart will help you more
              alt text

              taken from the documentation from here:
              https://doc.qt.io/qt-5/qtqml-cppintegration-overview.html


              Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


              Q: What's that?
              A: It's blue light.
              Q: What does it do?
              A: It turns blue.

              1 Reply Last reply
              4
              • D Offline
                D Offline
                damianatorrpm
                wrote on last edited by
                #7

                To an extend it does. The chart does not compare the advantages of using a singleton vs an uncreatable type if the singleton is not instantiated at all.

                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