Question about Component.onCompleted: signal handler
-
Can you please tell me why the
completed()signal is handled asComponent.onCompleted()? I want to know about theComponent.part.I understand that
completed()is a signal emitted by theComponentobject type of the QtQml module. But, I cannot understand why this signal is accessible in every QtQuick module object type as well.import QtQuick Item{ Component.onCompleted:{ console.log("Hello World") } } -
Component is a special type in the QtQml module that acts as a blueprint for creating objects in QML. Every QML object is implicitly part of a Component, even if you don't explicitly wrap it in a Component block. For example:
import QtQuick Item { Component.onCompleted: { console.log("Hello World") } }Internally, QML treats this as if it is wrapped in a Component:
import QtQuick Component { Item { Component.onCompleted: { console.log("Hello World") } } }You can analyze QQuickItem class and you will see that it inherits from QObject and QQmlParserStatus, hence it is possible to call Component.onCompleted() in Item objects.