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. Is a QML object type basically a class?

Is a QML object type basically a class?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
7 Posts 4 Posters 789 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.
  • Egn1n3E Offline
    Egn1n3E Offline
    Egn1n3
    wrote on last edited by
    #1

    Hi,
    I am trying to understand the concept of "QML object types". The Qt documentation says this about QML object types: A QML object type is a type from which a QML object can be instantiated.
    This seems to me that a QML object type is just the same as a class as you instantiate an object from it? Is that a valid statement?
    Thanks.

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

      Hi,

      Not completely. The next sentence in the documentation says QML object types are derived from QtObject, and are provided by QML modules.. So all these objects must be derived from QObject.

      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
      1
      • dheerendraD Offline
        dheerendraD Offline
        dheerendra
        Qt Champions 2022
        wrote on last edited by
        #3

        in addition what @SGaist said, if you are starting now with Qt/QML & coming from C++ background, you can just treat it like a class from which are creating the object in QML context.

        Dheerendra
        @Community Service
        Certified Qt Specialist
        http://www.pthinks.com

        1 Reply Last reply
        0
        • Egn1n3E Offline
          Egn1n3E Offline
          Egn1n3
          wrote on last edited by
          #4

          Thanks @SGaist and @dheerendra. So when you declare an QML Object type like this:

          import QtQuick 2.0
          
          Rectangle {
              width: 100
              height: 100
              color: "red"
          }
          

          The Rectangle Object type inherits the QObject class. But when will the Rectangle Object type be instantiated then? Or is this done automatically in QML once you declared it?
          Thanks.

          1 Reply Last reply
          0
          • dheerendraD Offline
            dheerendraD Offline
            dheerendra
            Qt Champions 2022
            wrote on last edited by
            #5

            Here it means to say that QML should create the object of Rectangle. That's it. Object of Rectangle is automatically created once you declare like above in your qml files.

            Dheerendra
            @Community Service
            Certified Qt Specialist
            http://www.pthinks.com

            1 Reply Last reply
            0
            • ODБOïO Offline
              ODБOïO Offline
              ODБOï
              wrote on last edited by
              #6

              https://qmlbook.github.io/en/ch16/index.html#understanding-the-qml-run-time

              Egn1n3E 1 Reply Last reply
              1
              • ODБOïO ODБOï

                https://qmlbook.github.io/en/ch16/index.html#understanding-the-qml-run-time

                Egn1n3E Offline
                Egn1n3E Offline
                Egn1n3
                wrote on last edited by
                #7

                @LeLev Thanks!

                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