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. Question about Component.onCompleted: signal handler
Forum Updated to NodeBB v4.3 + New Features

Question about Component.onCompleted: signal handler

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 177 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.
  • Ash VA Offline
    Ash VA Offline
    Ash V
    wrote on last edited by
    #1

    Can you please tell me why the completed() signal is handled as Component.onCompleted()? I want to know about the Component. part.

    I understand that completed() is a signal emitted by the Component object 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")
     }
    }
    
    1 Reply Last reply
    0
    • BondrusiekB Offline
      BondrusiekB Offline
      Bondrusiek
      wrote on last edited by Bondrusiek
      #2

      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.

      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