Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-35587

QML JS Incubator Fails to load component (regression)

    XMLWordPrintable

Details

    Description

      From the standard example from the documentation, the following code should create the button object asynchronously and initialise the parent and some properties.
      This worked fine in Qt 5.1.1 but does not work now in Qt 5.2.0.

      var component = Qt.createComponent("Button.qml");
      
      var incubator = component.incubateObject(parent, { x: 10, y: 10 });
      if (incubator.status != Component.Ready) {
          incubator.onStatusChanged = function(status) {
              if (status == Component.Ready) {
                  print ("Object", incubator.object, "is now ready!");
              }
          }
      } else {
          print ("Object", incubator.object, "is ready immediately!");
      }
      

      Note that the following code does work and can be used as a temporary workaround.

      var component;
      var button;
      
      function createObjects() {
          component = Qt.createComponent("Button.qml");
          if (component.status == Component.Ready)
              finishCreation();
          else
              component.statusChanged.connect(finishCreation);
      }
      
      function finishCreation() {
          if (component.status == Component.Ready) {
              button = component.createObject(parent, {"x": 10, "y": 10});
              if (button == null) {
                  // Error Handling
                  console.log("Error creating object");
              }
          } else if (component.status == Component.Error) {
              // Error Handling
              console.log("Error loading component:", component.errorString());
          }
      }
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            shausman Simon Hausmann
            miketrahearn Mike Trahearn
            Votes:
            2 Vote for this issue
            Watchers:
            11 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes