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. Enable QML error when loading objects dynamically
Qt 6.11 is out! See what's new in the release blog

Enable QML error when loading objects dynamically

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 666 Views 1 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.
  • M Offline
    M Offline
    Mark81
    wrote on last edited by
    #1

    I create a QML object on the fly in this way:

    let component;
    let sprite;
    
    function createSprite() {
        component = Qt.createComponent("sprites/MySprite.qml");
        sprite = component.createObject(window);
    }
    

    During the development I didn't see the object anymore and no errors were reported in the console.
    Removing this function and just declaring the object as usual:

    MySprite { }
    

    leads to output some errors, so I had the change to correct them.
    How to enable the usual error output even if the objects are loaded dynamically?

    jsulmJ 1 Reply Last reply
    0
    • M Mark81

      I create a QML object on the fly in this way:

      let component;
      let sprite;
      
      function createSprite() {
          component = Qt.createComponent("sprites/MySprite.qml");
          sprite = component.createObject(window);
      }
      

      During the development I didn't see the object anymore and no errors were reported in the console.
      Removing this function and just declaring the object as usual:

      MySprite { }
      

      leads to output some errors, so I had the change to correct them.
      How to enable the usual error output even if the objects are loaded dynamically?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Mark81 This is clearly explained in the documentation (https://doc.qt.io/qt-5/qml-qtqml-qt.html#createComponent-method):
      "The returned component's Component::status property indicates whether the component was successfully created. If the status is Component.Error, see Component::errorString() for an error description."

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      M 1 Reply Last reply
      0
      • jsulmJ jsulm

        @Mark81 This is clearly explained in the documentation (https://doc.qt.io/qt-5/qml-qtqml-qt.html#createComponent-method):
        "The returned component's Component::status property indicates whether the component was successfully created. If the status is Component.Error, see Component::errorString() for an error description."

        M Offline
        M Offline
        Mark81
        wrote on last edited by
        #3

        @jsulm Ok I didn't understand what this sentence actually says. Thanks for pointing out!

        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