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. Component.onCompleted events do not work
Forum Updated to NodeBB v4.3 + New Features

Component.onCompleted events do not work

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 1.6k Views 2 Watching
  • 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.
  • R Offline
    R Offline
    Rem-Kolomna
    wrote on last edited by
    #1

    Hi! I load one qml component into groupbox of another component using this code:

      QQmlComponent *comp = new QQmlComponent(engine, QUrl("qrc:/controllers/container.qml"), contentItem());
      QObject *obj = comp->create();
      QQmlProperty::write(obj, "parent"
                          , QVariant::fromValue<QObject*>(contentItem()));
      delete comp;
    

    But Component.onCreated event do not fires. How to fix this problem?
    PS: I do want to Component.onCreated be called after setting parent of loaded component

    p3c0P 1 Reply Last reply
    0
    • R Rem-Kolomna

      Hi! I load one qml component into groupbox of another component using this code:

        QQmlComponent *comp = new QQmlComponent(engine, QUrl("qrc:/controllers/container.qml"), contentItem());
        QObject *obj = comp->create();
        QQmlProperty::write(obj, "parent"
                            , QVariant::fromValue<QObject*>(contentItem()));
        delete comp;
      

      But Component.onCreated event do not fires. How to fix this problem?
      PS: I do want to Component.onCreated be called after setting parent of loaded component

      p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      @Rem-Kolomna If you use create() then Component.onCompleted will be called instantly. For more fine tuning you can use beginCreate followed by completeCreate thus calling the Component.onCompleted event. So according to your code:

      QQmlComponent *comp = new QQmlComponent(engine, QUrl("qrc:/controllers/container.qml"), contentItem());
      QQuickItem *childItem = qobject_cast<QQuickItem*>(component.beginCreate(engine->rootContext()));
      childItem->setParentItem(item); //set parent as your requirement
      qDebug() << "Before calling event";
      component.completeCreate();
      

      Try printing something inside Component.onCompleted of container.qml to notice the change.

      157

      1 Reply Last reply
      0
      • R Offline
        R Offline
        Rem-Kolomna
        wrote on last edited by
        #3

        thank you for suggestion! Now everything works like a charm!

        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