Important: Please read the Qt Code of Conduct -

Am I misunderstanding the docs, or is Qt.createQmlObject (almost) useless?

  • From the Qt docs:

    Note that this function returns immediately, and therefore may not work if the qml string loads new components (that is, external QML files that have not yet been loaded). If this is the case, consider using Qt.createComponent() instead.

    But as far as I know, all QML files are "external", and any of them may have its load delayed arbitrarily long.

    E.g. if I do this:

        import QtQuick 2.0\n\
        Rectangle { }

    What happens if Rectangle has not been loaded by the time I execute this code? By this logic any code that uses Qt.createQmlObject with imports in the passed string is risky. So we should always use Qt.createComponent instead.

    I'm pretty sure I'm misunderstanding these docs, but I don't know what the right interpretation of them is.

Log in to reply