let's see the structure of QML document

Structure of QML

the structure of QML has two parts

  • import statements
  • root object declaration



Import

QML document can import necessary modules and namespaces with "import statement". QML dosen't preprocess the import statements unlike other compiler languages such as C, C++ and JAVA. QML import just instruct the references to QML engine. QML document must import QtQuick module at least. and if QtQuick is imported, any QML document in the same directory can be referenced by default.


import QtQuick 2.0 //this import must be there

Item {
    width: 200
    height: 200
}



Object declaration

QML document describes the hierarchy of objects. and each object has its own type, id, properties, methods, signals and signal handlers. and you should be careful of that you have to declare just one root object in one QML documentation.



import QtQuick 2.0 //this import must be there

Item {
    id: root
    width: 200
    height: 200
    
    Item{
        id: child1
        width: 100
        height: 100
    }
    
    Item{
        id: child2
        width: 100
        height: 100
        
        item{
            id: child3
            width: 100
            height: 100
        }
    }
}

/* fail!!
Item {
    id: siblinng
    width: 200
    height: 200
}
*/

Comments

Popular posts from this blog

making menubar and menu on QML

let's start QML programming with PySide2

QSizePolicy Fixed example in pyside2