Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

[SOLVED]Qt.createQmlComponent and qrc



  • Hi all!

    I use QML in C++ resources and have stumbled on some weird behaviour. When I use Qt.createQmlComponent("import QtQuick 1.0; MyType{}) in my QML file and run it under QMLViewer it goes ok. But when I run it from my application it tells me "Error: Qt.createQmlComponent failed to create object: MyType is not a type". QML file MyType is in the resources and actively used by other components without any problems. Is it a bug or I missed something?



  • You're missing the correct import statement. When the qmlviewer runs it, it probably gets picked up with the implicit import "." but this doesn't seem to happen when run from the application in a script.

    You can file a bug anyways, because the behavior seems inconsistent and that alone is a bug. But you should be able to get it working if you explicitly import MyType instead of hoping the implicit imports pick it up. If the correct import statement still doesn't work, then it's definitely a bug.



  • aalpert, thank you for the clarification.


Log in to reply