Is a QML object type basically a class?
-
wrote on 10 Nov 2018, 21:32 last edited by
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. -
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 fromQObject
. -
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.
-
wrote on 11 Nov 2018, 08:24 last edited by
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. -
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.
-
wrote on 13 Nov 2018, 19:16 last edited by
@LeLev Thanks!
1/7